33#ifndef _GLIBCXX_OSTREAM
34#define _GLIBCXX_OSTREAM 1
37#pragma GCC system_header
43#if __cplusplus > 202002L
47# define __glibcxx_want_print
50namespace std _GLIBCXX_VISIBILITY(default)
52_GLIBCXX_BEGIN_NAMESPACE_VERSION
64 template<
typename _CharT,
typename _Traits>
65 inline basic_ostream<_CharT, _Traits>&
76 template<
typename _CharT,
typename _Traits>
77 inline basic_ostream<_CharT, _Traits>&
79 {
return __os.
put(_CharT()); }
86 template<
typename _CharT,
typename _Traits>
87 inline basic_ostream<_CharT, _Traits>&
89 {
return __os.
flush(); }
91#ifdef __glibcxx_syncbuf
92 template<
typename _CharT,
typename _Traits>
93 class __syncbuf_base :
public basic_streambuf<_CharT, _Traits>
97 _S_get(basic_streambuf<_CharT, _Traits>* __buf [[maybe_unused]])
noexcept
100 if (
auto __p =
dynamic_cast<__syncbuf_base*
>(__buf))
101 return &__p->_M_emit_on_sync;
107 __syncbuf_base(basic_streambuf<_CharT, _Traits>* __w =
nullptr)
111 basic_streambuf<_CharT, _Traits>* _M_wrapped =
nullptr;
112 bool _M_emit_on_sync =
false;
113 bool _M_needs_sync =
false;
116 template<
typename _CharT,
typename _Traits>
117 inline basic_ostream<_CharT, _Traits>&
118 emit_on_flush(basic_ostream<_CharT, _Traits>& __os)
120 if (
bool* __flag = __syncbuf_base<_CharT, _Traits>::_S_get(__os.rdbuf()))
125 template<
typename _CharT,
typename _Traits>
126 inline basic_ostream<_CharT, _Traits>&
127 noemit_on_flush(basic_ostream<_CharT, _Traits>& __os)
129 if (
bool* __flag = __syncbuf_base<_CharT, _Traits>::_S_get(__os.rdbuf()))
134 template<
typename _CharT,
typename _Traits>
135 inline basic_ostream<_CharT, _Traits>&
136 flush_emit(basic_ostream<_CharT, _Traits>& __os)
140 ~_Restore() { *_M_flag = _M_prev; }
142 bool _M_prev =
false;
143 bool* _M_flag = &_M_prev;
146 if (
bool* __flag = __syncbuf_base<_CharT, _Traits>::_S_get(__os.rdbuf()))
148 __restore._M_prev = *__flag;
149 __restore._M_flag = __flag;
160 vprint_nonunicode(
ostream& __os, string_view __fmt, format_args __args)
162 ostream::sentry __cerb(__os);
165 __format::_Str_sink<char> __buf;
166 std::vformat_to(__buf.out(), __os.getloc(), __fmt, __args);
167 auto __out = __buf.view();
171 std::__ostream_write(__os, __out.data(), __out.size());
176 __throw_exception_again;
184 vprint_unicode(
ostream& __os, string_view __fmt, format_args __args)
186#if !defined(_WIN32) || defined(__CYGWIN__)
189 std::vprint_nonunicode(__os, __fmt, __args);
191 ostream::sentry __cerb(__os);
194 __format::_Str_sink<char> __buf;
195 std::vformat_to(__buf.out(), __os.getloc(), __fmt, __args);
196 auto __out = __buf.view();
199 error_code __write_to_terminal(
void*, span<char>);
201 if (
auto __term = __open_terminal(__os.rdbuf()))
203#if !defined(_WIN32) || defined(__CYGWIN__)
210 _Guard(
void* __p) : _M_f((FILE*)__p) { }
211 ~_Guard() { std::fclose(_M_f); }
212 _Guard(_Guard&&) =
delete;
213 _Guard& operator=(_Guard&&) =
delete;
222 if (__os.rdbuf()->pubsync() == -1)
224 else if (
auto __e = __write_to_terminal(__term, __out))
231 __throw_exception_again;
237 __os.setstate(__err);
244 std::__ostream_write(__os, __out.data(), __out.size());
249 __throw_exception_again;
257 template<
typename... _Args>
259 print(
ostream& __os, format_string<_Args...> __fmt, _Args&&... __args)
261 auto __fmtargs = std::make_format_args(__args...);
262 if constexpr (__unicode::__literal_encoding_is_utf8())
263 std::vprint_unicode(__os, __fmt.get(), __fmtargs);
265 std::vprint_nonunicode(__os, __fmt.get(), __fmtargs);
268 template<
typename... _Args>
270 println(
ostream& __os, format_string<_Args...> __fmt, _Args&&... __args)
274 std::print(__os,
"{}\n", std::format(__os.getloc(), __fmt,
275 std::forward<_Args>(__args)...));
279 inline void println(
ostream& __os)
281#if defined(_WIN32) && !defined(__CYGWIN__)
282 if constexpr (__unicode::__literal_encoding_is_utf8())
283 std::vprint_unicode(__os,
"\n", std::make_format_args());
291_GLIBCXX_END_NAMESPACE_VERSION
error_code make_error_code(future_errc __errc) noexcept
Overload of make_error_code for future_errc.
basic_streambuf< char > streambuf
Base class for char buffers.
basic_ostream< char > ostream
Base class for char output streams.
ISO C++ entities toplevel namespace is std.
basic_ostream< _CharT, _Traits > & ends(basic_ostream< _CharT, _Traits > &__os)
Write a null character into the output sequence.
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
Write a newline and flush the stream.
basic_ostream< _CharT, _Traits > & flush(basic_ostream< _CharT, _Traits > &__os)
Flushes the output stream.
char_type widen(char __c) const
Widens characters.
Template class basic_ostream.
__ostream_type & put(char_type __c)
Simple insertion.
__ostream_type & flush()
Synchronizing the stream buffer.
Thrown as part of forced unwinding.
_Ios_Iostate iostate
This is a bitmask type.
static const iostate goodbit
Indicates all is well.
static const iostate badbit
Indicates a loss of integrity in an input or output sequence (such as an irrecoverable read error fro...