33 #ifndef _GLIBCXX_OSTREAM 34 #define _GLIBCXX_OSTREAM 1 36 #ifdef _GLIBCXX_SYSHDR 37 #pragma GCC system_header 43 #if __cplusplus > 202002L 47 # define __glibcxx_want_print 50 namespace 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>
79 {
return __os.
put(_CharT()); }
86 template<
typename _CharT,
typename _Traits>
89 {
return __os.
flush(); }
91 #ifdef __glibcxx_syncbuf // C++ >= 20 && HOSTED && CXX11ABI 92 template<
typename _CharT,
typename _Traits>
100 if (
auto __p = dynamic_cast<__syncbuf_base*>(__buf))
101 return &__p->_M_emit_on_sync;
112 bool _M_emit_on_sync =
false;
113 bool _M_needs_sync =
false;
116 template<
typename _CharT,
typename _Traits>
120 if (
bool* __flag = __syncbuf_base<_CharT, _Traits>::_S_get(__os.
rdbuf()))
125 template<
typename _CharT,
typename _Traits>
129 if (
bool* __flag = __syncbuf_base<_CharT, _Traits>::_S_get(__os.
rdbuf()))
134 template<
typename _CharT,
typename _Traits>
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;
156 #endif // __glibcxx_syncbuf 158 #if __cpp_lib_print // C++ >= 23 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;
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._M_span();
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;
224 else if (
auto __e = __write_to_terminal(__term, __out))
231 __throw_exception_again;
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 defined(_WIN32) && !defined(__CYGWIN__) 263 if constexpr (__unicode::__literal_encoding_is_utf8())
264 std::vprint_unicode(__os, __fmt.get(), __fmtargs);
267 std::vprint_nonunicode(__os, __fmt.get(), __fmtargs);
270 template<
typename... _Args>
272 println(
ostream& __os, format_string<_Args...> __fmt, _Args&&... __args)
274 auto __fmtargs = std::make_format_args(__args...);
276 __fmtn.
reserve(__fmt.get().size() + 1);
277 __fmtn = __fmt.get();
279 #if defined(_WIN32) && !defined(__CYGWIN__) 280 if constexpr (__unicode::__literal_encoding_is_utf8())
281 std::vprint_unicode(__os, __fmtn, __fmtargs);
284 std::vprint_nonunicode(__os, __fmtn, __fmtargs);
288 inline void println(
ostream& __os)
290 #if defined(_WIN32) && !defined(__CYGWIN__) 291 if constexpr (__unicode::__literal_encoding_is_utf8())
292 std::vprint_unicode(__os,
"\n", std::make_format_args());
298 #endif // __cpp_lib_print 300 _GLIBCXX_END_NAMESPACE_VERSION
int pubsync()
Calls virtual sync function.
basic_streambuf< _CharT, _Traits > * rdbuf() const
Accessing the underlying buffer.
__ostream_type & put(char_type __c)
Simple insertion.
static const iostate badbit
Indicates a loss of integrity in an input or output sequence (such as an irrecoverable read error fro...
static const iostate goodbit
Indicates all is well.
basic_ostream< _CharT, _Traits > & flush(basic_ostream< _CharT, _Traits > &__os)
Flushes the output stream.
__ostream_type & flush()
Synchronizing the stream buffer.
Template class basic_ostream.
error_code make_error_code(future_errc __errc) noexcept
Overload of make_error_code for future_errc.
ISO C++ entities toplevel namespace is std.
A non-owning reference to a string.
basic_ostream< _CharT, _Traits > & ends(basic_ostream< _CharT, _Traits > &__os)
Write a null character into the output sequence.
void reserve(size_type __res_arg)
Attempt to preallocate enough memory for specified number of characters.
Thrown as part of forced unwinding.A magic placeholder class that can be caught by reference to recog...
char_type widen(char __c) const
Widens characters.
locale getloc() const
Locale access.
void setstate(iostate __state)
Sets additional flags in the error state.
The actual work of input and output (interface).
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
Write a newline and flush the stream.