123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197 |
- // -*- 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 <__memory/shared_ptr.h>
- #include <__memory/unique_ptr.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 > 20
- _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 > 14
- // 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_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_NO_EXCEPTIONS
- if (__os_.rdbuf()->pubsync() == -1)
- __os_.setstate(ios_base::badbit);
- #ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- }
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_NO_EXCEPTIONS
- sentry __s(*this);
- if (__s)
- {
- if (__sb)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_failbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- else
- this->setstate(ios_base::badbit);
- }
- #ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(bool __n)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(short __n)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(int __n)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(long __n)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(long long __n)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(float __n)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(double __n)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(long double __n)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- }
- catch (...)
- {
- __os.__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- }
- catch (...)
- {
- __os.__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- }
- catch (...)
- {
- __os.__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_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_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_NO_EXCEPTIONS
- sentry __sen(*this);
- if (__sen && __n)
- {
- if (this->rdbuf()->sputn(__s, __n) != __n)
- this->setstate(ios_base::badbit);
- }
- #ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- return *this;
- }
- template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>&
- basic_ostream<_CharT, _Traits>::flush()
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_NO_EXCEPTIONS
- if (this->rdbuf())
- {
- sentry __s(*this);
- if (__s)
- {
- if (this->rdbuf()->pubsync() == -1)
- this->setstate(ios_base::badbit);
- }
- }
- #ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- this->__set_badbit_and_consider_rethrow();
- }
- #endif // _LIBCPP_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, class = typename enable_if<
- _And<is_base_of<ios_base, _Stream>,
- __is_ostreamable<_Stream&, const _Tp&> >::value
- >::type>
- _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>
- inline _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_same<void, __void_t<decltype((std::declval<basic_ostream<_CharT, _Traits>&>() << std::declval<typename unique_ptr<_Yp, _Dp>::pointer>()))> >::value,
- basic_ostream<_CharT, _Traits>&
- >::type
- 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 > 17
- 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 <concepts>
- # include <iterator>
- # include <type_traits>
- #endif
- #endif // _LIBCPP_OSTREAM
|