From 3ad39e9878310e5317ee73c9b353c1e2c1c5c4ee Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Sat, 11 Jul 2026 22:48:30 +0800 Subject: lib: establish Zircon libc++ and KTL foundation --- .../include/c++/v1/__ostream/basic_ostream.h | 681 +++++++++++++++++++++ .../libcxx/include/c++/v1/__ostream/print.h | 172 ++++++ .../c++/v1/__ostream/put_character_sequence.h | 59 ++ 3 files changed, 912 insertions(+) create mode 100644 third_party/libcxx/include/c++/v1/__ostream/basic_ostream.h create mode 100644 third_party/libcxx/include/c++/v1/__ostream/print.h create mode 100644 third_party/libcxx/include/c++/v1/__ostream/put_character_sequence.h (limited to 'third_party/libcxx/include/c++/v1/__ostream') diff --git a/third_party/libcxx/include/c++/v1/__ostream/basic_ostream.h b/third_party/libcxx/include/c++/v1/__ostream/basic_ostream.h new file mode 100644 index 0000000..62770be --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__ostream/basic_ostream.h @@ -0,0 +1,681 @@ +//===---------------------------------------------------------------------===// +// +// 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_BASIC_OSTREAM_H +#define _LIBCPP___OSTREAM_BASIC_OSTREAM_H + +#include <__config> + +#if _LIBCPP_HAS_LOCALIZATION + +# include <__exception/operations.h> +# include <__fwd/memory.h> +# include <__iterator/ostreambuf_iterator.h> +# include <__locale_dir/num.h> +# include <__locale_dir/pad_and_output.h> +# include <__memory/addressof.h> +# include <__memory/unique_ptr.h> +# include <__new/exceptions.h> +# include <__ostream/put_character_sequence.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 +# include +# include +# include + +# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +# endif + +_LIBCPP_PUSH_MACROS +# include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +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: + inline _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 explicit basic_ostream(basic_streambuf* __sb) { + this->init(__sb); + } + ~basic_ostream() override; + + basic_ostream(const basic_ostream& __rhs) = delete; + basic_ostream& operator=(const basic_ostream& __rhs) = delete; + +protected: + inline _LIBCPP_HIDE_FROM_ABI basic_ostream(basic_ostream&& __rhs); + + // 27.7.2.3 Assign/swap + inline _LIBCPP_HIDE_FROM_ABI basic_ostream& operator=(basic_ostream&& __rhs); + + inline _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 void swap(basic_ostream& __rhs) { + basic_ios::swap(__rhs); + } + +public: + // 27.7.2.4 Prefix/suffix: + class sentry; + + // 27.7.2.6 Formatted output: + inline _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&)) { + return __pf(*this); + } + + inline _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 basic_ostream& + operator<<(basic_ios& (*__pf)(basic_ios&)) { + __pf(*this); + return *this; + } + + inline _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&)) { + __pf(*this); + return *this; + } + + template + _LIBCPP_HIDE_FROM_ABI basic_ostream& __put_num(_Tp __value) { +# if _LIBCPP_HAS_EXCEPTIONS + try { +# endif // _LIBCPP_HAS_EXCEPTIONS + sentry __s(*this); + if (__s) { + using _Fp = num_put >; + const _Fp& __facet = std::use_facet<_Fp>(this->getloc()); + if (__facet.put(*this, *this, this->fill(), __value).failed()) + this->setstate(ios_base::badbit | ios_base::failbit); + } +# if _LIBCPP_HAS_EXCEPTIONS + } catch (...) { + this->__set_badbit_and_consider_rethrow(); + } +# endif // _LIBCPP_HAS_EXCEPTIONS + return *this; + } + + template + _LIBCPP_HIDE_FROM_ABI basic_ostream& __put_num_integer_promote(_Tp __value) { +# if _LIBCPP_HAS_EXCEPTIONS + try { +# endif // _LIBCPP_HAS_EXCEPTIONS + sentry __s(*this); + if (__s) { + ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield; + + using _Fp = num_put >; + const _Fp& __facet = std::use_facet<_Fp>(this->getloc()); + if (__facet + .put(*this, + *this, + this->fill(), + __flags == ios_base::oct || __flags == ios_base::hex + ? static_cast<__copy_unsigned_t<_Tp, long> >(std::__to_unsigned_like(__value)) + : static_cast<__copy_unsigned_t<_Tp, long> >(__value)) + .failed()) + this->setstate(ios_base::badbit | ios_base::failbit); + } +# if _LIBCPP_HAS_EXCEPTIONS + } catch (...) { + this->__set_badbit_and_consider_rethrow(); + } +# endif // _LIBCPP_HAS_EXCEPTIONS + 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(__p)); + } +# endif + + basic_ostream& operator<<(basic_streambuf* __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_HIDE_FROM_ABI 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: + [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 pos_type tellp(); + inline _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 basic_ostream& seekp(pos_type __pos); + inline _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir); + +protected: + _LIBCPP_HIDE_FROM_ABI basic_ostream() {} // extension, intentially does not initialize +}; + +template +class 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_HIDE_FROM_ABI explicit operator bool() const { return __ok_; } +}; + +template +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 +basic_ostream<_CharT, _Traits>::sentry::~sentry() { + if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf) && uncaught_exceptions() == 0) { +# if _LIBCPP_HAS_EXCEPTIONS + try { +# endif // _LIBCPP_HAS_EXCEPTIONS + if (__os_.rdbuf()->pubsync() == -1) + __os_.setstate(ios_base::badbit); +# if _LIBCPP_HAS_EXCEPTIONS + } catch (...) { + } +# endif // _LIBCPP_HAS_EXCEPTIONS + } +} + +template +basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs) { + this->move(__rhs); +} + +template +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs) { + swap(__rhs); + return *this; +} + +template +basic_ostream<_CharT, _Traits>::~basic_ostream() {} + +template +basic_ostream<_CharT, _Traits>& +basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf* __sb) { +# if _LIBCPP_HAS_EXCEPTIONS + try { +# endif // _LIBCPP_HAS_EXCEPTIONS + sentry __s(*this); + if (__s) { + if (__sb) { +# if _LIBCPP_HAS_EXCEPTIONS + try { +# endif // _LIBCPP_HAS_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); +# if _LIBCPP_HAS_EXCEPTIONS + } catch (...) { + this->__set_failbit_and_consider_rethrow(); + } +# endif // _LIBCPP_HAS_EXCEPTIONS + } else + this->setstate(ios_base::badbit); + } +# if _LIBCPP_HAS_EXCEPTIONS + } catch (...) { + this->__set_badbit_and_consider_rethrow(); + } +# endif // _LIBCPP_HAS_EXCEPTIONS + return *this; +} + +template +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(bool __n) { + return __put_num(__n); +} + +template +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(short __n) { + return __put_num_integer_promote(__n); +} + +template +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n) { + return __put_num_integer_promote(__n); +} + +template +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(int __n) { + return __put_num_integer_promote(__n); +} + +template +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n) { + return __put_num_integer_promote(__n); +} + +template +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long __n) { + return __put_num(__n); +} + +template +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n) { + return __put_num(__n); +} + +template +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long long __n) { + return __put_num(__n); +} + +template +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n) { + return __put_num(__n); +} + +template +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(float __n) { + return *this << static_cast(__n); +} + +template +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(double __n) { + return __put_num(__n); +} + +template +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long double __n) { + return __put_num(__n); +} + +template +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(const void* __n) { + return __put_num(__n); +} + +template +_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c) { + return std::__put_character_sequence(__os, std::addressof(__c), 1); +} + +template +_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn) { +# if _LIBCPP_HAS_EXCEPTIONS + try { +# endif // _LIBCPP_HAS_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), + std::addressof(__c), + std::addressof(__c) + (((__os.flags() & ios_base::adjustfield) == ios_base::left) ? 1 : 0), + std::addressof(__c) + 1, + __os, + __os.fill()) + .failed()) + __os.setstate(ios_base::badbit | ios_base::failbit); + } +# if _LIBCPP_HAS_EXCEPTIONS + } catch (...) { + __os.__set_badbit_and_consider_rethrow(); + } +# endif // _LIBCPP_HAS_EXCEPTIONS + return __os; +} + +template +_LIBCPP_HIDE_FROM_ABI basic_ostream& operator<<(basic_ostream& __os, char __c) { + return std::__put_character_sequence(__os, &__c, 1); +} + +template +_LIBCPP_HIDE_FROM_ABI basic_ostream& operator<<(basic_ostream& __os, signed char __c) { + return std::__put_character_sequence(__os, (char*)&__c, 1); +} + +template +_LIBCPP_HIDE_FROM_ABI basic_ostream& operator<<(basic_ostream& __os, unsigned char __c) { + return std::__put_character_sequence(__os, (char*)&__c, 1); +} + +template +_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str) { + return std::__put_character_sequence(__os, __str, _Traits::length(__str)); +} + +template +_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn) { +# if _LIBCPP_HAS_EXCEPTIONS + try { +# endif // _LIBCPP_HAS_EXCEPTIONS + typename basic_ostream<_CharT, _Traits>::sentry __s(__os); + if (__s) { + typedef ostreambuf_iterator<_CharT, _Traits> _Ip; + size_t __len = char_traits::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) + std::__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); + } +# if _LIBCPP_HAS_EXCEPTIONS + } catch (...) { + __os.__set_badbit_and_consider_rethrow(); + } +# endif // _LIBCPP_HAS_EXCEPTIONS + return __os; +} + +template +_LIBCPP_HIDE_FROM_ABI basic_ostream& operator<<(basic_ostream& __os, const char* __str) { + return std::__put_character_sequence(__os, __str, _Traits::length(__str)); +} + +template +_LIBCPP_HIDE_FROM_ABI basic_ostream& +operator<<(basic_ostream& __os, const signed char* __str) { + const char* __s = (const char*)__str; + return std::__put_character_sequence(__os, __s, _Traits::length(__s)); +} + +template +_LIBCPP_HIDE_FROM_ABI basic_ostream& +operator<<(basic_ostream& __os, const unsigned char* __str) { + const char* __s = (const char*)__str; + return std::__put_character_sequence(__os, __s, _Traits::length(__s)); +} + +template +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::put(char_type __c) { +# if _LIBCPP_HAS_EXCEPTIONS + try { +# endif // _LIBCPP_HAS_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); + } +# if _LIBCPP_HAS_EXCEPTIONS + } catch (...) { + this->__set_badbit_and_consider_rethrow(); + } +# endif // _LIBCPP_HAS_EXCEPTIONS + return *this; +} + +template +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n) { +# if _LIBCPP_HAS_EXCEPTIONS + try { +# endif // _LIBCPP_HAS_EXCEPTIONS + sentry __sen(*this); + if (__sen && __n) { + if (this->rdbuf()->sputn(__s, __n) != __n) + this->setstate(ios_base::badbit); + } +# if _LIBCPP_HAS_EXCEPTIONS + } catch (...) { + this->__set_badbit_and_consider_rethrow(); + } +# endif // _LIBCPP_HAS_EXCEPTIONS + return *this; +} + +template +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::flush() { +# if _LIBCPP_HAS_EXCEPTIONS + try { +# endif // _LIBCPP_HAS_EXCEPTIONS + if (this->rdbuf()) { + sentry __s(*this); + if (__s) { + if (this->rdbuf()->pubsync() == -1) + this->setstate(ios_base::badbit); + } + } +# if _LIBCPP_HAS_EXCEPTIONS + } catch (...) { + this->__set_badbit_and_consider_rethrow(); + } +# endif // _LIBCPP_HAS_EXCEPTIONS + return *this; +} + +template +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 +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 +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 +_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 +_LIBCPP_HIDE_FROM_ABI inline basic_ostream<_CharT, _Traits>& ends(basic_ostream<_CharT, _Traits>& __os) { + __os.put(_CharT()); + return __os; +} + +template +_LIBCPP_HIDE_FROM_ABI inline basic_ostream<_CharT, _Traits>& flush(basic_ostream<_CharT, _Traits>& __os) { + __os.flush(); + return __os; +} + +template +struct __is_ostreamable : false_type {}; + +template +struct __is_ostreamable<_Stream, _Tp, decltype(std::declval<_Stream>() << std::declval<_Tp>(), void())> : true_type {}; + +template , __is_ostreamable<_Stream&, const _Tp&> >::value, int> = 0> +_LIBCPP_HIDE_FROM_ABI _Stream&& operator<<(_Stream&& __os, const _Tp& __x) { + __os << __x; + return std::move(__os); +} + +template +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const basic_string<_CharT, _Traits, _Allocator>& __str) { + return std::__put_character_sequence(__os, __str.data(), __str.size()); +} + +template +_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, basic_string_view<_CharT, _Traits> __sv) { + return std::__put_character_sequence(__os, __sv.data(), __sv.size()); +} + +template +inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec) { + return __os << __ec.category().name() << ':' << __ec.value(); +} + +template +inline _LIBCPP_HIDE_FROM_ABI 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&>() + << std::declval::pointer>()))> >::value, + int> = 0> +inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p) { + return __os << __p.get(); +} + +template +_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 >(__os.getloc()).widen('0'), + std::use_facet >(__os.getloc()).widen('1')); +} + +# if _LIBCPP_STD_VER >= 20 + +# if _LIBCPP_HAS_WIDE_CHARACTERS +template +basic_ostream& operator<<(basic_ostream&, wchar_t) = delete; + +template +basic_ostream& operator<<(basic_ostream&, const wchar_t*) = delete; + +template +basic_ostream& operator<<(basic_ostream&, char16_t) = delete; + +template +basic_ostream& operator<<(basic_ostream&, char32_t) = delete; + +template +basic_ostream& operator<<(basic_ostream&, const char16_t*) = delete; + +template +basic_ostream& operator<<(basic_ostream&, const char32_t*) = delete; + +# endif // _LIBCPP_HAS_WIDE_CHARACTERS + +# if _LIBCPP_HAS_CHAR8_T +template +basic_ostream& operator<<(basic_ostream&, char8_t) = delete; + +template +basic_ostream& operator<<(basic_ostream&, char8_t) = delete; + +template +basic_ostream& operator<<(basic_ostream&, const char8_t*) = delete; + +template +basic_ostream& operator<<(basic_ostream&, const char8_t*) = delete; +# endif + +template +basic_ostream& operator<<(basic_ostream&, char16_t) = delete; + +template +basic_ostream& operator<<(basic_ostream&, char32_t) = delete; + +template +basic_ostream& operator<<(basic_ostream&, const char16_t*) = delete; + +template +basic_ostream& operator<<(basic_ostream&, const char32_t*) = delete; + +# endif // _LIBCPP_STD_VER >= 20 + +extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream; +# if _LIBCPP_HAS_WIDE_CHARACTERS +extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream; +# endif + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_HAS_LOCALIZATION + +#endif // _LIBCPP___OSTREAM_BASIC_OSTREAM_H diff --git a/third_party/libcxx/include/c++/v1/__ostream/print.h b/third_party/libcxx/include/c++/v1/__ostream/print.h new file mode 100644 index 0000000..6b6c903 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__ostream/print.h @@ -0,0 +1,172 @@ +//===---------------------------------------------------------------------===// +// +// 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_PRINT_H +#define _LIBCPP___OSTREAM_PRINT_H + +#include <__config> + +#if _LIBCPP_HAS_LOCALIZATION + +# include <__fwd/ostream.h> +# include <__iterator/ostreambuf_iterator.h> +# include <__ostream/basic_ostream.h> +# include +# include +# include +# include + +# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +# endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +# if _LIBCPP_STD_VER >= 23 + +template // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563). +_LIBCPP_HIDE_FROM_ABI inline void +__vprint_nonunicode(ostream& __os, string_view __fmt, format_args __args, bool __write_nl) { + // [ostream.formatted.print]/3 + // Effects: Behaves as a formatted output function + // ([ostream.formatted.reqmts]) of os, except that: + // - failure to generate output is reported as specified below, and + // - any exception thrown by the call to vformat is propagated without regard + // to the value of os.exceptions() and without turning on ios_base::badbit + // in the error state of os. + // After constructing a sentry object, the function initializes an automatic + // variable via + // string out = vformat(os.getloc(), fmt, args); + + ostream::sentry __s(__os); + if (__s) { + string __o = std::vformat(__os.getloc(), __fmt, __args); + if (__write_nl) + __o += '\n'; + +# if _LIBCPP_HAS_EXCEPTIONS + try { +# endif // _LIBCPP_HAS_EXCEPTIONS + if (auto __rdbuf = __os.rdbuf(); + !__rdbuf || __rdbuf->sputn(__o.data(), __o.size()) != static_cast(__o.size())) + __os.setstate(ios_base::badbit | ios_base::failbit); + +# if _LIBCPP_HAS_EXCEPTIONS + } catch (...) { + __os.__set_badbit_and_consider_rethrow(); + } +# endif // _LIBCPP_HAS_EXCEPTIONS + } +} + +template // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563). +_LIBCPP_HIDE_FROM_ABI inline void vprint_nonunicode(ostream& __os, string_view __fmt, format_args __args) { + std::__vprint_nonunicode(__os, __fmt, __args, false); +} + +// Returns the FILE* associated with the __os. +// Returns a nullptr when no FILE* is associated with __os. +// This function is in the dylib since the type of the buffer associated +// with std::cout, std::cerr, and std::clog is only known in the dylib. +// +// This function implements part of the implementation-defined behavior +// of [ostream.formatted.print]/3 +// If the function is vprint_unicode and os is a stream that refers to +// a terminal capable of displaying Unicode which is determined in an +// implementation-defined manner, writes out to the terminal using the +// native Unicode API; +// Whether the returned FILE* is "a terminal capable of displaying Unicode" +// is determined in the same way as the print(FILE*, ...) overloads. +_LIBCPP_EXPORTED_FROM_ABI FILE* __get_ostream_file(ostream& __os); + +# if _LIBCPP_HAS_UNICODE +template // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563). +_LIBCPP_HIDE_FROM_ABI void __vprint_unicode(ostream& __os, string_view __fmt, format_args __args, bool __write_nl) { +# ifndef _LIBCPP_WIN32API + return std::__vprint_nonunicode(__os, __fmt, __args, __write_nl); +# else + FILE* __file = std::__get_ostream_file(__os); + if (!__file || !__print::__is_terminal(__file)) + return std::__vprint_nonunicode(__os, __fmt, __args, __write_nl); + + // [ostream.formatted.print]/3 + // If the function is vprint_unicode and os is a stream that refers to a + // terminal capable of displaying Unicode which is determined in an + // implementation-defined manner, writes out to the terminal using the + // native Unicode API; if out contains invalid code units, the behavior is + // undefined and implementations are encouraged to diagnose it. If the + // native Unicode API is used, the function flushes os before writing out. + // + // This is the path for the native API, start with flushing. + __os.flush(); + +# if _LIBCPP_HAS_EXCEPTIONS + try { +# endif // _LIBCPP_HAS_EXCEPTIONS + ostream::sentry __s(__os); + if (__s) { +# if _LIBCPP_HAS_WIDE_CHARACTERS + __print::__vprint_unicode_windows(__file, __fmt, __args, __write_nl); +# else +# error "Windows builds with wchar_t disabled are not supported." +# endif + } + +# if _LIBCPP_HAS_EXCEPTIONS + } catch (...) { + __os.__set_badbit_and_consider_rethrow(); + } +# endif // _LIBCPP_HAS_EXCEPTIONS +# endif // _LIBCPP_WIN32API +} + +template // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563). +_LIBCPP_HIDE_FROM_ABI inline void vprint_unicode(ostream& __os, string_view __fmt, format_args __args) { + std::__vprint_unicode(__os, __fmt, __args, false); +} +# endif // _LIBCPP_HAS_UNICODE + +template +_LIBCPP_HIDE_FROM_ABI void print(ostream& __os, format_string<_Args...> __fmt, _Args&&... __args) { +# if _LIBCPP_HAS_UNICODE + if constexpr (__print::__use_unicode_execution_charset) + std::__vprint_unicode(__os, __fmt.get(), std::make_format_args(__args...), false); + else + std::__vprint_nonunicode(__os, __fmt.get(), std::make_format_args(__args...), false); +# else // _LIBCPP_HAS_UNICODE + std::__vprint_nonunicode(__os, __fmt.get(), std::make_format_args(__args...), false); +# endif // _LIBCPP_HAS_UNICODE +} + +template +_LIBCPP_HIDE_FROM_ABI void println(ostream& __os, format_string<_Args...> __fmt, _Args&&... __args) { +# if _LIBCPP_HAS_UNICODE + // Note the wording in the Standard is inefficient. The output of + // std::format is a std::string which is then copied. This solution + // just appends a newline at the end of the output. + if constexpr (__print::__use_unicode_execution_charset) + std::__vprint_unicode(__os, __fmt.get(), std::make_format_args(__args...), true); + else + std::__vprint_nonunicode(__os, __fmt.get(), std::make_format_args(__args...), true); +# else // _LIBCPP_HAS_UNICODE + std::__vprint_nonunicode(__os, __fmt.get(), std::make_format_args(__args...), true); +# endif // _LIBCPP_HAS_UNICODE +} + +template // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563). +_LIBCPP_HIDE_FROM_ABI inline void println(ostream& __os) { + std::print(__os, "\n"); +} + +# endif // _LIBCPP_STD_VER >= 23 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_HAS_LOCALIZATION + +#endif // _LIBCPP___OSTREAM_PRINT_H diff --git a/third_party/libcxx/include/c++/v1/__ostream/put_character_sequence.h b/third_party/libcxx/include/c++/v1/__ostream/put_character_sequence.h new file mode 100644 index 0000000..aa771b3 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/__ostream/put_character_sequence.h @@ -0,0 +1,59 @@ +//===---------------------------------------------------------------------===// +// +// 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_PUT_CHARACTER_SEQUENCE_H +#define _LIBCPP___OSTREAM_PUT_CHARACTER_SEQUENCE_H + +#include <__config> + +#if _LIBCPP_HAS_LOCALIZATION + +# include <__cstddef/size_t.h> +# include <__fwd/ostream.h> +# include <__iterator/ostreambuf_iterator.h> +# include <__locale_dir/pad_and_output.h> +# include + +# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +# endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& +__put_character_sequence(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str, size_t __len) { +# if _LIBCPP_HAS_EXCEPTIONS + try { +# endif // _LIBCPP_HAS_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); + } +# if _LIBCPP_HAS_EXCEPTIONS + } catch (...) { + __os.__set_badbit_and_consider_rethrow(); + } +# endif // _LIBCPP_HAS_EXCEPTIONS + return __os; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_HAS_LOCALIZATION + +#endif // _LIBCPP___OSTREAM_PUT_CHARACTER_SEQUENCE_H -- cgit v1.2.3