33#ifndef _GLIBCXX_OSTREAM
34#define _GLIBCXX_OSTREAM 1
36#pragma GCC system_header
42#if __cplusplus > 202002L
46# define __glibcxx_want_print
49namespace std _GLIBCXX_VISIBILITY(default)
51_GLIBCXX_BEGIN_NAMESPACE_VERSION
65 template<
typename _CharT,
typename _Traits>
70 typedef _CharT char_type;
71 typedef typename _Traits::int_type int_type;
72 typedef typename _Traits::pos_type pos_type;
73 typedef typename _Traits::off_type off_type;
74 typedef _Traits traits_type;
175 {
return _M_insert(__n); }
179 {
return _M_insert(__n); }
183 {
return _M_insert(__n); }
193 return _M_insert(
static_cast<unsigned long>(__n));
204 return _M_insert(
static_cast<unsigned long>(__n));
207#ifdef _GLIBCXX_USE_LONG_LONG
210 {
return _M_insert(__n); }
214 {
return _M_insert(__n); }
229 {
return _M_insert(__f); }
236 return _M_insert(
static_cast<double>(__f));
241 {
return _M_insert(__f); }
244#if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
245 __attribute__((__always_inline__))
249 return _M_insert(
static_cast<double>(__f));
253#if defined(__STDCPP_FLOAT32_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
254 __attribute__((__always_inline__))
258 return _M_insert(
static_cast<double>(__f));
262#if defined(__STDCPP_FLOAT64_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
263 __attribute__((__always_inline__))
267 return _M_insert(
static_cast<double>(__f));
271#if defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128)
272 __attribute__((__always_inline__))
276 return _M_insert(
static_cast<long double>(__f));
280#if defined(__STDCPP_BFLOAT16_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
281 __attribute__((__always_inline__))
285 return _M_insert(
static_cast<double>(__f));
299 {
return _M_insert(__p); }
301#if __cplusplus >= 201703L
304 {
return *
this <<
"nullptr"; }
307#if __cplusplus > 202002L
308 __attribute__((__always_inline__))
311 {
return _M_insert(
const_cast<const void*
>(__p)); }
440#if __cplusplus >= 201103L
448 { __ios_type::move(__rhs); }
455 operator=(basic_ostream&& __rhs)
462 swap(basic_ostream& __rhs)
463 { __ios_type::swap(__rhs); }
466 template<
typename _ValueT>
468 _M_insert(_ValueT __v);
471#if !_GLIBCXX_INLINE_VERSION
473 _M_write(
const char_type* __s,
streamsize __n)
474 { std::__ostream_insert(*
this, __s, __n); }
485 template <
typename _CharT,
typename _Traits>
507#pragma GCC diagnostic push
508#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
522 if (_M_os.
rdbuf() && _M_os.
rdbuf()->pubsync() == -1)
526#pragma GCC diagnostic pop
535#if __cplusplus >= 201103L
538 operator bool()
const
558 template<
typename _CharT,
typename _Traits>
562 if (__out.
width() != 0)
563 return __ostream_insert(__out, &__c, 1);
568 template<
typename _CharT,
typename _Traits>
569 inline basic_ostream<_CharT, _Traits>&
570 operator<<(basic_ostream<_CharT, _Traits>& __out,
char __c)
571 {
return (__out << __out.widen(__c)); }
574 template<
typename _Traits>
575 inline basic_ostream<char, _Traits>&
576 operator<<(basic_ostream<char, _Traits>& __out,
char __c)
578 if (__out.width() != 0)
579 return __ostream_insert(__out, &__c, 1);
585 template<
typename _Traits>
586 inline basic_ostream<char, _Traits>&
587 operator<<(basic_ostream<char, _Traits>& __out,
signed char __c)
588 {
return (__out <<
static_cast<char>(__c)); }
590 template<
typename _Traits>
591 inline basic_ostream<char, _Traits>&
592 operator<<(basic_ostream<char, _Traits>& __out,
unsigned char __c)
593 {
return (__out <<
static_cast<char>(__c)); }
595#if __cplusplus > 201703L
599 template<
typename _Traits>
600 basic_ostream<char, _Traits>&
601 operator<<(basic_ostream<char, _Traits>&,
wchar_t) =
delete;
603#ifdef _GLIBCXX_USE_CHAR8_T
604 template<
typename _Traits>
605 basic_ostream<char, _Traits>&
606 operator<<(basic_ostream<char, _Traits>&,
char8_t) =
delete;
609 template<
typename _Traits>
610 basic_ostream<char, _Traits>&
611 operator<<(basic_ostream<char, _Traits>&,
char16_t) =
delete;
613 template<
typename _Traits>
614 basic_ostream<char, _Traits>&
615 operator<<(basic_ostream<char, _Traits>&,
char32_t) =
delete;
617#ifdef _GLIBCXX_USE_WCHAR_T
618#ifdef _GLIBCXX_USE_CHAR8_T
619 template<
typename _Traits>
620 basic_ostream<wchar_t, _Traits>&
621 operator<<(basic_ostream<wchar_t, _Traits>&,
char8_t) =
delete;
624 template<
typename _Traits>
625 basic_ostream<wchar_t, _Traits>&
626 operator<<(basic_ostream<wchar_t, _Traits>&,
char16_t) =
delete;
628 template<
typename _Traits>
629 basic_ostream<wchar_t, _Traits>&
630 operator<<(basic_ostream<wchar_t, _Traits>&,
char32_t) =
delete;
649 template<
typename _CharT,
typename _Traits>
650 inline basic_ostream<_CharT, _Traits>&
651 operator<<(basic_ostream<_CharT, _Traits>& __out,
const _CharT* __s)
656 __ostream_insert(__out, __s,
657 static_cast<streamsize>(_Traits::length(__s)));
661 template<
typename _CharT,
typename _Traits>
662 basic_ostream<_CharT, _Traits> &
663 operator<<(basic_ostream<_CharT, _Traits>& __out,
const char* __s);
666 template<
typename _Traits>
667 inline basic_ostream<char, _Traits>&
668 operator<<(basic_ostream<char, _Traits>& __out,
const char* __s)
673 __ostream_insert(__out, __s,
674 static_cast<streamsize>(_Traits::length(__s)));
679 template<
typename _Traits>
680 inline basic_ostream<char, _Traits>&
681 operator<<(basic_ostream<char, _Traits>& __out,
const signed char* __s)
682 {
return (__out <<
reinterpret_cast<const char*
>(__s)); }
684 template<
typename _Traits>
685 inline basic_ostream<char, _Traits> &
686 operator<<(basic_ostream<char, _Traits>& __out,
const unsigned char* __s)
687 {
return (__out <<
reinterpret_cast<const char*
>(__s)); }
689#if __cplusplus > 201703L
693 template<
typename _Traits>
694 basic_ostream<char, _Traits>&
695 operator<<(basic_ostream<char, _Traits>&,
const wchar_t*) =
delete;
697#ifdef _GLIBCXX_USE_CHAR8_T
698 template<
typename _Traits>
699 basic_ostream<char, _Traits>&
700 operator<<(basic_ostream<char, _Traits>&,
const char8_t*) =
delete;
703 template<
typename _Traits>
704 basic_ostream<char, _Traits>&
705 operator<<(basic_ostream<char, _Traits>&,
const char16_t*) =
delete;
707 template<
typename _Traits>
708 basic_ostream<char, _Traits>&
709 operator<<(basic_ostream<char, _Traits>&,
const char32_t*) =
delete;
711#ifdef _GLIBCXX_USE_WCHAR_T
712#ifdef _GLIBCXX_USE_CHAR8_T
713 template<
typename _Traits>
714 basic_ostream<wchar_t, _Traits>&
715 operator<<(basic_ostream<wchar_t, _Traits>&,
const char8_t*) =
delete;
718 template<
typename _Traits>
719 basic_ostream<wchar_t, _Traits>&
720 operator<<(basic_ostream<wchar_t, _Traits>&,
const char16_t*) =
delete;
722 template<
typename _Traits>
723 basic_ostream<wchar_t, _Traits>&
724 operator<<(basic_ostream<wchar_t, _Traits>&,
const char32_t*) =
delete;
739 template<
typename _CharT,
typename _Traits>
740 inline basic_ostream<_CharT, _Traits>&
751 template<
typename _CharT,
typename _Traits>
752 inline basic_ostream<_CharT, _Traits>&
754 {
return __os.
put(_CharT()); }
761 template<
typename _CharT,
typename _Traits>
762 inline basic_ostream<_CharT, _Traits>&
764 {
return __os.
flush(); }
766#if __cplusplus >= 201103L
771#if __cpp_concepts >= 201907L && __glibcxx_type_trait_variable_templates
773 template<
typename _Tp>
774 concept __derived_from_ios_base = is_class_v<_Tp>
775 && (!is_same_v<_Tp, ios_base>)
776 &&
requires (_Tp* __t, ios_base* __b) { __b = __t; };
778 template<
typename _Os,
typename _Tp>
779 requires __derived_from_ios_base<_Os>
780 &&
requires (_Os& __os,
const _Tp& __t) { __os << __t; }
781 using __rvalue_stream_insertion_t = _Os&&;
783 template<
typename _Tp>
784 using _Require_derived_from_ios_base
785 = _Require<is_class<_Tp>, __not_<is_same<_Tp, ios_base>>,
786 is_convertible<typename add_pointer<_Tp>::type, ios_base*>>;
788 template<
typename _Os,
typename _Tp,
789 typename = _Require_derived_from_ios_base<_Os>,
791 =
decltype(std::declval<_Os&>() << std::declval<const _Tp&>())>
792 using __rvalue_stream_insertion_t = _Os&&;
805 template<
typename _Ostream,
typename _Tp>
806 inline __rvalue_stream_insertion_t<_Ostream, _Tp>
813#ifdef __glibcxx_syncbuf
814 template<
typename _CharT,
typename _Traits>
815 class __syncbuf_base :
public basic_streambuf<_CharT, _Traits>
819 _S_get(basic_streambuf<_CharT, _Traits>* __buf [[maybe_unused]])
noexcept
822 if (
auto __p =
dynamic_cast<__syncbuf_base*
>(__buf))
823 return &__p->_M_emit_on_sync;
829 __syncbuf_base(basic_streambuf<_CharT, _Traits>* __w =
nullptr)
833 basic_streambuf<_CharT, _Traits>* _M_wrapped =
nullptr;
834 bool _M_emit_on_sync =
false;
835 bool _M_needs_sync =
false;
838 template<
typename _CharT,
typename _Traits>
839 inline basic_ostream<_CharT, _Traits>&
840 emit_on_flush(basic_ostream<_CharT, _Traits>& __os)
842 if (
bool* __flag = __syncbuf_base<_CharT, _Traits>::_S_get(__os.rdbuf()))
847 template<
typename _CharT,
typename _Traits>
848 inline basic_ostream<_CharT, _Traits>&
849 noemit_on_flush(basic_ostream<_CharT, _Traits>& __os)
851 if (
bool* __flag = __syncbuf_base<_CharT, _Traits>::_S_get(__os.rdbuf()))
856 template<
typename _CharT,
typename _Traits>
857 inline basic_ostream<_CharT, _Traits>&
858 flush_emit(basic_ostream<_CharT, _Traits>& __os)
862 ~_Restore() { *_M_flag = _M_prev; }
864 bool _M_prev =
false;
865 bool* _M_flag = &_M_prev;
868 if (
bool* __flag = __syncbuf_base<_CharT, _Traits>::_S_get(__os.rdbuf()))
870 __restore._M_prev = *__flag;
871 __restore._M_flag = __flag;
883 vprint_nonunicode(
ostream& __os, string_view __fmt, format_args __args)
885 ostream::sentry __cerb(__os);
888 __format::_Str_sink<char> __buf;
889 std::vformat_to(__buf.out(), __os.getloc(), __fmt, __args);
890 auto __out = __buf.view();
894 std::__ostream_write(__os, __out.data(), __out.size());
899 __throw_exception_again;
907 vprint_unicode(
ostream& __os, string_view __fmt, format_args __args)
909#if !defined(_WIN32) || defined(__CYGWIN__)
912 std::vprint_nonunicode(__os, __fmt, __args);
914 ostream::sentry __cerb(__os);
917 __format::_Str_sink<char> __buf;
918 std::vformat_to(__buf.out(), __os.getloc(), __fmt, __args);
919 auto __out = __buf.view();
922 error_code __write_to_terminal(
void*, span<char>);
924 if (
auto __term = __open_terminal(__os.rdbuf()))
926#if !defined(_WIN32) || defined(__CYGWIN__)
933 _Guard(
void* __p) : _M_f((FILE*)__p) { }
934 ~_Guard() { std::fclose(_M_f); }
935 _Guard(_Guard&&) =
delete;
936 _Guard& operator=(_Guard&&) =
delete;
945 if (__os.rdbuf()->pubsync() == -1)
947 else if (
auto __e = __write_to_terminal(__term, __out))
954 __throw_exception_again;
960 __os.setstate(__err);
967 std::__ostream_write(__os, __out.data(), __out.size());
972 __throw_exception_again;
980 template<
typename... _Args>
982 print(
ostream& __os, format_string<_Args...> __fmt, _Args&&... __args)
984 auto __fmtargs = std::make_format_args(__args...);
985 if constexpr (__unicode::__literal_encoding_is_utf8())
986 std::vprint_unicode(__os, __fmt.get(), __fmtargs);
988 std::vprint_nonunicode(__os, __fmt.get(), __fmtargs);
991 template<
typename... _Args>
993 println(
ostream& __os, format_string<_Args...> __fmt, _Args&&... __args)
995 std::print(__os,
"{}\n",
996 std::format(__fmt, std::forward<_Args>(__args)...));
1000 inline void println(
ostream& __os)
1002#if defined(_WIN32) && !defined(__CYGWIN__)
1003 if constexpr (__unicode::__literal_encoding_is_utf8())
1004 std::vprint_unicode(__os,
"\n", std::make_format_args());
1014_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.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
bool uncaught_exception() noexcept
ISO C++ entities toplevel namespace is std.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
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.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
Template class basic_ios, virtual base class for all stream classes.
void setstate(iostate __state)
Sets additional flags in the error state.
void init(basic_streambuf< _CharT, _Traits > *__sb)
All setup is performed here.
char_type widen(char __c) const
Widens characters.
basic_streambuf< _CharT, _Traits > * rdbuf() const
Accessing the underlying buffer.
The actual work of input and output (interface).
Template class basic_ostream.
__ostream_type & write(const char_type *__s, streamsize __n)
Character string insertion.
pos_type tellp()
Getting the current write position.
__ostream_type & put(char_type __c)
Simple insertion.
basic_ostream(__streambuf_type *__sb)
Base constructor.
__ostream_type & flush()
Synchronizing the stream buffer.
__ostream_type & seekp(pos_type)
Changing the current write position.
virtual ~basic_ostream()
Base destructor.
__ostream_type & operator<<(__ostream_type &(*__pf)(__ostream_type &))
Interface for manipulators.
Performs setup work for output streams.
~sentry()
Possibly flushes the stream.
Thrown as part of forced unwinding.
The base of the I/O class hierarchy.
_Ios_Iostate iostate
This is a bitmask type.
fmtflags flags() const
Access to format flags.
static const iostate goodbit
Indicates all is well.
static const fmtflags unitbuf
Flushes output after each output operation.
static const iostate badbit
Indicates a loss of integrity in an input or output sequence (such as an irrecoverable read error fro...
streamsize width() const
Flags access.
_Ios_Seekdir seekdir
This is an enumerated type.
Primary class template ctype facet.
Primary class template num_put.