33#ifndef _GLIBCXX_OSTREAM
34#define _GLIBCXX_OSTREAM 1
37#pragma GCC system_header
44#if __cplusplus > 202002L
48# define __glibcxx_want_print
51namespace std _GLIBCXX_VISIBILITY(default)
53_GLIBCXX_BEGIN_NAMESPACE_VERSION
67 template<
typename _CharT,
typename _Traits>
72 typedef _CharT char_type;
73 typedef typename _Traits::int_type int_type;
74 typedef typename _Traits::pos_type pos_type;
75 typedef typename _Traits::off_type off_type;
76 typedef _Traits traits_type;
177 {
return _M_insert(__n); }
181 {
return _M_insert(__n); }
185 {
return _M_insert(__n); }
195 return _M_insert(
static_cast<unsigned long>(__n));
206 return _M_insert(
static_cast<unsigned long>(__n));
209#ifdef _GLIBCXX_USE_LONG_LONG
210#pragma GCC diagnostic push
211#pragma GCC diagnostic ignored "-Wlong-long"
214 {
return _M_insert(__n); }
218 {
return _M_insert(__n); }
219#pragma GCC diagnostic pop
234 {
return _M_insert(__f); }
241 return _M_insert(_S_cast_flt<double>(__f));
246 {
return _M_insert(__f); }
249#if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
250 __attribute__((__always_inline__))
254 return _M_insert(_S_cast_flt<double>(__f));
258#if defined(__STDCPP_FLOAT32_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
259 __attribute__((__always_inline__))
263 return _M_insert(_S_cast_flt<double>(__f));
267#if defined(__STDCPP_FLOAT64_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
268 __attribute__((__always_inline__))
272 return _M_insert(_S_cast_flt<double>(__f));
276#if defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128)
277 __attribute__((__always_inline__))
281 return _M_insert(_S_cast_flt<long double>(__f));
285#if defined(__STDCPP_BFLOAT16_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
286 __attribute__((__always_inline__))
290 return _M_insert(_S_cast_flt<double>(__f));
304 {
return _M_insert(__p); }
306#if __cplusplus >= 201703L
309 {
return *
this <<
"nullptr"; }
312#if __cplusplus > 202002L
313 __attribute__((__always_inline__))
316 {
return _M_insert(
const_cast<const void*
>(__p)); }
445#if __cplusplus >= 201103L
453 { __ios_type::move(__rhs); }
460 operator=(basic_ostream&& __rhs)
467 swap(basic_ostream& __rhs)
468 { __ios_type::swap(__rhs); }
471 template<
typename _ValueT>
473 _M_insert(_ValueT __v);
476#if !_GLIBCXX_INLINE_VERSION
478 _M_write(
const char_type* __s,
streamsize __n)
479 { std::__ostream_insert(*
this, __s, __n); }
482#pragma GCC diagnostic push
483#pragma GCC diagnostic ignored "-Wc++17-extensions"
484 template<
typename _To,
typename _From>
486 _S_cast_flt(_From __f)
488 _To __d =
static_cast<_To
>(__f);
493#if __cpp_constexpr && __has_builtin(__builtin_bit_cast)
494 if constexpr (
sizeof(__f) ==
sizeof(
short))
495 __sign =
static_cast<_To
>(__builtin_bit_cast(
short, __f));
496 else if constexpr (
sizeof(__f) ==
sizeof(
int))
497 __sign =
static_cast<_To
>(__builtin_bit_cast(
int, __f));
498 else if constexpr (
sizeof(__f) ==
sizeof(
long long))
499 __sign =
static_cast<_To
>(__builtin_bit_cast(
long long, __f));
502 __sign = __builtin_signbit(__f) ? _To(-1.0) : _To(+1.0);
504 if _GLIBCXX17_CONSTEXPR (__is_same(_To,
double))
505 __d = __builtin_copysign(__d, __sign);
506 else if _GLIBCXX17_CONSTEXPR (__is_same(_To,
long double))
507 __d = __builtin_copysignl(__d, __sign);
512#pragma GCC diagnostic pop
521 template <
typename _CharT,
typename _Traits>
543#pragma GCC diagnostic push
544#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
558 if (_M_os.
rdbuf() && _M_os.
rdbuf()->pubsync() == -1)
562#pragma GCC diagnostic pop
571#if __cplusplus >= 201103L
574 operator bool()
const
594 template<
typename _CharT,
typename _Traits>
598 if (__out.
width() != 0)
599 return __ostream_insert(__out, &__c, 1);
604 template<
typename _CharT,
typename _Traits>
605 inline basic_ostream<_CharT, _Traits>&
606 operator<<(basic_ostream<_CharT, _Traits>& __out,
char __c)
607 {
return (__out << __out.widen(__c)); }
610 template<
typename _Traits>
611 inline basic_ostream<char, _Traits>&
612 operator<<(basic_ostream<char, _Traits>& __out,
char __c)
614 if (__out.width() != 0)
615 return __ostream_insert(__out, &__c, 1);
621 template<
typename _Traits>
622 inline basic_ostream<char, _Traits>&
623 operator<<(basic_ostream<char, _Traits>& __out,
signed char __c)
624 {
return (__out <<
static_cast<char>(__c)); }
626 template<
typename _Traits>
627 inline basic_ostream<char, _Traits>&
628 operator<<(basic_ostream<char, _Traits>& __out,
unsigned char __c)
629 {
return (__out <<
static_cast<char>(__c)); }
631#if __cplusplus > 201703L
635 template<
typename _Traits>
636 basic_ostream<char, _Traits>&
637 operator<<(basic_ostream<char, _Traits>&,
wchar_t) =
delete;
639#ifdef _GLIBCXX_USE_CHAR8_T
640 template<
typename _Traits>
641 basic_ostream<char, _Traits>&
642 operator<<(basic_ostream<char, _Traits>&,
char8_t) =
delete;
645 template<
typename _Traits>
646 basic_ostream<char, _Traits>&
647 operator<<(basic_ostream<char, _Traits>&,
char16_t) =
delete;
649 template<
typename _Traits>
650 basic_ostream<char, _Traits>&
651 operator<<(basic_ostream<char, _Traits>&,
char32_t) =
delete;
653#ifdef _GLIBCXX_USE_WCHAR_T
654#ifdef _GLIBCXX_USE_CHAR8_T
655 template<
typename _Traits>
656 basic_ostream<wchar_t, _Traits>&
657 operator<<(basic_ostream<wchar_t, _Traits>&,
char8_t) =
delete;
660 template<
typename _Traits>
661 basic_ostream<wchar_t, _Traits>&
662 operator<<(basic_ostream<wchar_t, _Traits>&,
char16_t) =
delete;
664 template<
typename _Traits>
665 basic_ostream<wchar_t, _Traits>&
666 operator<<(basic_ostream<wchar_t, _Traits>&,
char32_t) =
delete;
685 template<
typename _CharT,
typename _Traits>
686 inline basic_ostream<_CharT, _Traits>&
687 operator<<(basic_ostream<_CharT, _Traits>& __out,
const _CharT* __s)
692 __ostream_insert(__out, __s,
693 static_cast<streamsize>(_Traits::length(__s)));
697 template<
typename _CharT,
typename _Traits>
698 basic_ostream<_CharT, _Traits> &
699 operator<<(basic_ostream<_CharT, _Traits>& __out,
const char* __s);
702 template<
typename _Traits>
703 inline basic_ostream<char, _Traits>&
704 operator<<(basic_ostream<char, _Traits>& __out,
const char* __s)
709 __ostream_insert(__out, __s,
710 static_cast<streamsize>(_Traits::length(__s)));
715 template<
typename _Traits>
716 inline basic_ostream<char, _Traits>&
717 operator<<(basic_ostream<char, _Traits>& __out,
const signed char* __s)
718 {
return (__out <<
reinterpret_cast<const char*
>(__s)); }
720 template<
typename _Traits>
721 inline basic_ostream<char, _Traits> &
722 operator<<(basic_ostream<char, _Traits>& __out,
const unsigned char* __s)
723 {
return (__out <<
reinterpret_cast<const char*
>(__s)); }
725#if __cplusplus > 201703L
729 template<
typename _Traits>
730 basic_ostream<char, _Traits>&
731 operator<<(basic_ostream<char, _Traits>&,
const wchar_t*) =
delete;
733#ifdef _GLIBCXX_USE_CHAR8_T
734 template<
typename _Traits>
735 basic_ostream<char, _Traits>&
736 operator<<(basic_ostream<char, _Traits>&,
const char8_t*) =
delete;
739 template<
typename _Traits>
740 basic_ostream<char, _Traits>&
741 operator<<(basic_ostream<char, _Traits>&,
const char16_t*) =
delete;
743 template<
typename _Traits>
744 basic_ostream<char, _Traits>&
745 operator<<(basic_ostream<char, _Traits>&,
const char32_t*) =
delete;
747#ifdef _GLIBCXX_USE_WCHAR_T
748#ifdef _GLIBCXX_USE_CHAR8_T
749 template<
typename _Traits>
750 basic_ostream<wchar_t, _Traits>&
751 operator<<(basic_ostream<wchar_t, _Traits>&,
const char8_t*) =
delete;
754 template<
typename _Traits>
755 basic_ostream<wchar_t, _Traits>&
756 operator<<(basic_ostream<wchar_t, _Traits>&,
const char16_t*) =
delete;
758 template<
typename _Traits>
759 basic_ostream<wchar_t, _Traits>&
760 operator<<(basic_ostream<wchar_t, _Traits>&,
const char32_t*) =
delete;
775 template<
typename _CharT,
typename _Traits>
776 inline basic_ostream<_CharT, _Traits>&
787 template<
typename _CharT,
typename _Traits>
788 inline basic_ostream<_CharT, _Traits>&
790 {
return __os.
put(_CharT()); }
797 template<
typename _CharT,
typename _Traits>
798 inline basic_ostream<_CharT, _Traits>&
800 {
return __os.
flush(); }
802#if __cplusplus >= 201103L
807#if __cpp_concepts >= 201907L && __glibcxx_type_trait_variable_templates
809 template<
typename _Tp>
810 concept __derived_from_ios_base = is_class_v<_Tp>
811 && (!is_same_v<_Tp, ios_base>)
812 &&
requires (_Tp* __t, ios_base* __b) { __b = __t; };
814 template<
typename _Os,
typename _Tp>
815 requires __derived_from_ios_base<_Os>
816 &&
requires (_Os& __os,
const _Tp& __t) { __os << __t; }
817 using __rvalue_stream_insertion_t = _Os&&;
819 template<
typename _Tp>
820 using _Require_derived_from_ios_base
821 = _Require<is_class<_Tp>, __not_<is_same<_Tp, ios_base>>,
822 is_convertible<typename add_pointer<_Tp>::type, ios_base*>>;
824 template<
typename _Os,
typename _Tp,
825 typename = _Require_derived_from_ios_base<_Os>,
827 =
decltype(std::declval<_Os&>() << std::declval<const _Tp&>())>
828 using __rvalue_stream_insertion_t = _Os&&;
841 template<
typename _Ostream,
typename _Tp>
842 inline __rvalue_stream_insertion_t<_Ostream, _Tp>
849#ifdef __glibcxx_syncbuf
850 template<
typename _CharT,
typename _Traits>
851 class __syncbuf_base :
public basic_streambuf<_CharT, _Traits>
855 _S_get(basic_streambuf<_CharT, _Traits>* __buf [[maybe_unused]])
noexcept
858 if (
auto __p =
dynamic_cast<__syncbuf_base*
>(__buf))
859 return &__p->_M_emit_on_sync;
865 __syncbuf_base(basic_streambuf<_CharT, _Traits>* __w =
nullptr)
869 basic_streambuf<_CharT, _Traits>* _M_wrapped =
nullptr;
870 bool _M_emit_on_sync =
false;
871 bool _M_needs_sync =
false;
874 template<
typename _CharT,
typename _Traits>
875 inline basic_ostream<_CharT, _Traits>&
876 emit_on_flush(basic_ostream<_CharT, _Traits>& __os)
878 if (
bool* __flag = __syncbuf_base<_CharT, _Traits>::_S_get(__os.rdbuf()))
883 template<
typename _CharT,
typename _Traits>
884 inline basic_ostream<_CharT, _Traits>&
885 noemit_on_flush(basic_ostream<_CharT, _Traits>& __os)
887 if (
bool* __flag = __syncbuf_base<_CharT, _Traits>::_S_get(__os.rdbuf()))
892 template<
typename _CharT,
typename _Traits>
893 inline basic_ostream<_CharT, _Traits>&
894 flush_emit(basic_ostream<_CharT, _Traits>& __os)
898 ~_Restore() { *_M_flag = _M_prev; }
900 bool _M_prev =
false;
901 bool* _M_flag = &_M_prev;
904 if (
bool* __flag = __syncbuf_base<_CharT, _Traits>::_S_get(__os.rdbuf()))
906 __restore._M_prev = *__flag;
907 __restore._M_flag = __flag;
919 vprint_nonunicode(
ostream& __os, string_view __fmt, format_args __args)
921 ostream::sentry __cerb(__os);
924 __format::_Str_sink<char> __buf;
925 std::vformat_to(__buf.out(), __os.getloc(), __fmt, __args);
926 auto __out = __buf.view();
930 std::__ostream_write(__os, __out.data(), __out.size());
935 __throw_exception_again;
943 vprint_unicode(
ostream& __os, string_view __fmt, format_args __args)
945#if !defined(_WIN32) || defined(__CYGWIN__)
948 std::vprint_nonunicode(__os, __fmt, __args);
950 ostream::sentry __cerb(__os);
953 __format::_Str_sink<char> __buf;
954 std::vformat_to(__buf.out(), __os.getloc(), __fmt, __args);
955 auto __out = __buf.view();
958 error_code __write_to_terminal(
void*, span<char>);
960 if (
auto __term = __open_terminal(__os.rdbuf()))
962#if !defined(_WIN32) || defined(__CYGWIN__)
969 _Guard(
void* __p) : _M_f((FILE*)__p) { }
970 ~_Guard() { std::fclose(_M_f); }
971 _Guard(_Guard&&) =
delete;
972 _Guard& operator=(_Guard&&) =
delete;
981 if (__os.rdbuf()->pubsync() == -1)
983 else if (
auto __e = __write_to_terminal(__term, __out))
990 __throw_exception_again;
996 __os.setstate(__err);
1003 std::__ostream_write(__os, __out.data(), __out.size());
1008 __throw_exception_again;
1016 template<
typename... _Args>
1018 print(
ostream& __os, format_string<_Args...> __fmt, _Args&&... __args)
1020 auto __fmtargs = std::make_format_args(__args...);
1021 if constexpr (__unicode::__literal_encoding_is_utf8())
1022 std::vprint_unicode(__os, __fmt.get(), __fmtargs);
1024 std::vprint_nonunicode(__os, __fmt.get(), __fmtargs);
1027 template<
typename... _Args>
1029 println(
ostream& __os, format_string<_Args...> __fmt, _Args&&... __args)
1031 std::print(__os,
"{}\n",
1032 std::format(__fmt, std::forward<_Args>(__args)...));
1036 inline void println(
ostream& __os)
1038#if defined(_WIN32) && !defined(__CYGWIN__)
1039 if constexpr (__unicode::__literal_encoding_is_utf8())
1040 std::vprint_unicode(__os,
"\n", std::make_format_args());
1050_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.