34 #ifndef _GLIBCXX_OSTREAM_H 35 #define _GLIBCXX_OSTREAM_H 1 37 #ifdef _GLIBCXX_SYSHDR 38 #pragma GCC system_header 46 # define __glibcxx_want_print 49 namespace std _GLIBCXX_VISIBILITY(default)
51 _GLIBCXX_BEGIN_NAMESPACE_VERSION
65 template<
typename _CharT,
typename _Traits>
66 class basic_ostream :
virtual public basic_ios<_CharT, _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;
77 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
78 typedef basic_ios<_CharT, _Traits> __ios_type;
79 typedef basic_ostream<_CharT, _Traits> __ostream_type;
80 typedef num_put<_CharT, ostreambuf_iterator<_CharT, _Traits> >
82 typedef ctype<_CharT> __ctype_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 208 #pragma GCC diagnostic push 209 #pragma GCC diagnostic ignored "-Wlong-long" 212 {
return _M_insert(__n); }
216 {
return _M_insert(__n); }
217 #pragma GCC diagnostic pop 232 {
return _M_insert(__f); }
239 return _M_insert(_S_cast_flt<double>(__f));
244 {
return _M_insert(__f); }
247 #if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64) 248 __attribute__((__always_inline__))
252 return _M_insert(_S_cast_flt<double>(__f));
256 #if defined(__STDCPP_FLOAT32_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64) 257 __attribute__((__always_inline__))
261 return _M_insert(_S_cast_flt<double>(__f));
265 #if defined(__STDCPP_FLOAT64_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64) 266 __attribute__((__always_inline__))
270 return _M_insert(_S_cast_flt<double>(__f));
274 #if defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128) 275 __attribute__((__always_inline__))
279 return _M_insert(_S_cast_flt<long double>(__f));
283 #if defined(__STDCPP_BFLOAT16_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64) 284 __attribute__((__always_inline__))
288 return _M_insert(_S_cast_flt<double>(__f));
302 {
return _M_insert(__p); }
304 #if __cplusplus >= 201703L 307 {
return *
this <<
"nullptr"; }
310 #if __cplusplus > 202002L 311 __attribute__((__always_inline__))
314 {
return _M_insert(const_cast<const void*>(__p)); }
443 #if __cplusplus >= 201103L 458 operator=(basic_ostream&& __rhs)
465 swap(basic_ostream& __rhs)
466 { __ios_type::swap(__rhs); }
469 template<
typename _ValueT>
471 _M_insert(_ValueT __v);
474 #if !_GLIBCXX_INLINE_VERSION 476 _M_write(
const char_type* __s,
streamsize __n)
477 { std::__ostream_insert(*
this, __s, __n); }
480 #pragma GCC diagnostic push 481 #pragma GCC diagnostic ignored "-Wc++17-extensions" // for if-constexpr 482 template<
typename _To,
typename _From>
484 _S_cast_flt(_From __f)
486 _To __d =
static_cast<_To
>(__f);
491 #if __cpp_constexpr && __has_builtin(__builtin_bit_cast) 492 if constexpr (
sizeof(__f) ==
sizeof(
short))
493 __sign =
static_cast<_To
>(__builtin_bit_cast(
short, __f));
494 else if constexpr (
sizeof(__f) ==
sizeof(
int))
495 __sign =
static_cast<_To
>(__builtin_bit_cast(
int, __f));
496 else if constexpr (
sizeof(__f) ==
sizeof(
long long))
497 __sign =
static_cast<_To
>(__builtin_bit_cast(
long long, __f));
500 __sign = __builtin_signbit(__f) ? _To(-1.0) : _To(+1.0);
502 if _GLIBCXX17_CONSTEXPR (__is_same(_To,
double))
503 __d = __builtin_copysign(__d, __sign);
504 else if _GLIBCXX17_CONSTEXPR (__is_same(_To,
long double))
505 __d = __builtin_copysignl(__d, __sign);
509 #pragma GCC diagnostic pop 512 struct _Disable_exceptions
514 _Disable_exceptions(basic_ostream& __os)
515 : _M_os(__os), _M_exception(_M_os._M_exception)
518 ~_Disable_exceptions()
519 { _M_os._M_exception = _M_exception; }
521 #pragma GCC diagnostic push 522 #pragma GCC diagnostic ignored "-Wc++11-extensions" // deleted functions 523 _Disable_exceptions(
const _Disable_exceptions&) =
delete;
524 _Disable_exceptions& operator=(
const _Disable_exceptions&) =
delete;
525 #pragma GCC diagnostic pop 528 basic_ostream& _M_os;
540 template <
typename _CharT,
typename _Traits>
562 #pragma GCC diagnostic push 563 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 580 _Disable_exceptions __noex(_M_os);
585 if (_M_os.rdbuf() && _M_os.rdbuf()->pubsync() == -1)
592 #pragma GCC diagnostic pop 601 #if __cplusplus >= 201103L 604 operator bool()
const 624 template<
typename _CharT,
typename _Traits>
626 operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
628 if (__out.width() != 0)
629 return __ostream_insert(__out, &__c, 1);
634 template<
typename _CharT,
typename _Traits>
635 inline basic_ostream<_CharT, _Traits>&
636 operator<<(basic_ostream<_CharT, _Traits>& __out,
char __c)
637 {
return (__out << __out.widen(__c)); }
640 template<
typename _Traits>
641 inline basic_ostream<char, _Traits>&
642 operator<<(basic_ostream<char, _Traits>& __out,
char __c)
644 if (__out.width() != 0)
645 return __ostream_insert(__out, &__c, 1);
651 template<
typename _Traits>
652 inline basic_ostream<char, _Traits>&
653 operator<<(basic_ostream<char, _Traits>& __out,
signed char __c)
654 {
return (__out << static_cast<char>(__c)); }
656 template<
typename _Traits>
657 inline basic_ostream<char, _Traits>&
658 operator<<(basic_ostream<char, _Traits>& __out,
unsigned char __c)
659 {
return (__out << static_cast<char>(__c)); }
661 #if __cplusplus > 201703L 665 template<
typename _Traits>
666 basic_ostream<char, _Traits>&
667 operator<<(basic_ostream<char, _Traits>&, wchar_t) =
delete;
669 #ifdef _GLIBCXX_USE_CHAR8_T 670 template<
typename _Traits>
671 basic_ostream<char, _Traits>&
672 operator<<(basic_ostream<char, _Traits>&, char8_t) =
delete;
675 template<
typename _Traits>
676 basic_ostream<char, _Traits>&
677 operator<<(basic_ostream<char, _Traits>&, char16_t) =
delete;
679 template<
typename _Traits>
680 basic_ostream<char, _Traits>&
681 operator<<(basic_ostream<char, _Traits>&, char32_t) =
delete;
683 #ifdef _GLIBCXX_USE_WCHAR_T 684 #ifdef _GLIBCXX_USE_CHAR8_T 685 template<
typename _Traits>
686 basic_ostream<wchar_t, _Traits>&
687 operator<<(basic_ostream<wchar_t, _Traits>&, char8_t) =
delete;
688 #endif // _GLIBCXX_USE_CHAR8_T 690 template<
typename _Traits>
691 basic_ostream<wchar_t, _Traits>&
692 operator<<(basic_ostream<wchar_t, _Traits>&, char16_t) =
delete;
694 template<
typename _Traits>
695 basic_ostream<wchar_t, _Traits>&
696 operator<<(basic_ostream<wchar_t, _Traits>&, char32_t) =
delete;
697 #endif // _GLIBCXX_USE_WCHAR_T 715 template<
typename _CharT,
typename _Traits>
716 inline basic_ostream<_CharT, _Traits>&
717 operator<<(basic_ostream<_CharT, _Traits>& __out,
const _CharT* __s)
722 __ostream_insert(__out, __s,
723 static_cast<streamsize>(_Traits::length(__s)));
727 template<
typename _CharT,
typename _Traits>
728 basic_ostream<_CharT, _Traits> &
729 operator<<(basic_ostream<_CharT, _Traits>& __out,
const char* __s);
732 template<
typename _Traits>
733 inline basic_ostream<char, _Traits>&
734 operator<<(basic_ostream<char, _Traits>& __out,
const char* __s)
739 __ostream_insert(__out, __s,
740 static_cast<streamsize>(_Traits::length(__s)));
745 template<
typename _Traits>
746 inline basic_ostream<char, _Traits>&
747 operator<<(basic_ostream<char, _Traits>& __out,
const signed char* __s)
748 {
return (__out << reinterpret_cast<const char*>(__s)); }
750 template<
typename _Traits>
751 inline basic_ostream<char, _Traits> &
752 operator<<(basic_ostream<char, _Traits>& __out,
const unsigned char* __s)
753 {
return (__out << reinterpret_cast<const char*>(__s)); }
755 #if __cplusplus > 201703L 759 template<
typename _Traits>
760 basic_ostream<char, _Traits>&
761 operator<<(basic_ostream<char, _Traits>&,
const wchar_t*) =
delete;
763 #ifdef _GLIBCXX_USE_CHAR8_T 764 template<
typename _Traits>
765 basic_ostream<char, _Traits>&
766 operator<<(basic_ostream<char, _Traits>&,
const char8_t*) =
delete;
767 #endif // _GLIBCXX_USE_CHAR8_T 769 template<
typename _Traits>
770 basic_ostream<char, _Traits>&
771 operator<<(basic_ostream<char, _Traits>&,
const char16_t*) =
delete;
773 template<
typename _Traits>
774 basic_ostream<char, _Traits>&
775 operator<<(basic_ostream<char, _Traits>&,
const char32_t*) =
delete;
777 #ifdef _GLIBCXX_USE_WCHAR_T 778 #ifdef _GLIBCXX_USE_CHAR8_T 779 template<
typename _Traits>
780 basic_ostream<wchar_t, _Traits>&
781 operator<<(basic_ostream<wchar_t, _Traits>&,
const char8_t*) =
delete;
784 template<
typename _Traits>
785 basic_ostream<wchar_t, _Traits>&
786 operator<<(basic_ostream<wchar_t, _Traits>&,
const char16_t*) =
delete;
788 template<
typename _Traits>
789 basic_ostream<wchar_t, _Traits>&
790 operator<<(basic_ostream<wchar_t, _Traits>&,
const char32_t*) =
delete;
791 #endif // _GLIBCXX_USE_WCHAR_T 795 #if __cplusplus >= 201103L 800 #if __cpp_concepts >= 201907L && __glibcxx_type_trait_variable_templates 802 template<
typename _Tp>
803 concept __derived_from_ios_base = is_class_v<_Tp>
804 && (!is_same_v<_Tp, ios_base>)
805 && requires (_Tp* __t, ios_base* __b) { __b = __t; };
807 template<
typename _Os,
typename _Tp>
808 requires __derived_from_ios_base<_Os>
809 && requires (_Os& __os,
const _Tp& __t) { __os << __t; }
810 using __rvalue_stream_insertion_t = _Os&&;
812 template<
typename _Tp>
813 using _Require_derived_from_ios_base
814 = _Require<is_class<_Tp>, __not_<is_same<_Tp, ios_base>>,
815 is_convertible<typename add_pointer<_Tp>::type, ios_base*>>;
817 template<
typename _Os,
typename _Tp,
818 typename = _Require_derived_from_ios_base<_Os>,
820 = decltype(std::declval<_Os&>() << std::declval<const _Tp&>())>
821 using __rvalue_stream_insertion_t = _Os&&;
834 template<
typename _Ostream,
typename _Tp>
835 inline __rvalue_stream_insertion_t<_Ostream, _Tp>
843 _GLIBCXX_END_NAMESPACE_VERSION
__ostream_type & flush()
Synchronizing the stream buffer.
__ostream_type & seekp(pos_type)
Changing the current write position.
static const fmtflags unitbuf
Flushes output after each output operation.
void init(basic_streambuf< _CharT, _Traits > *__sb)
All setup is performed here.
The base of the I/O class hierarchy.This class defines everything that can be defined about I/O that ...
~sentry()
Possibly flushes the stream.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
basic_ostream(__streambuf_type *__sb)
Base constructor.
_Ios_Iostate iostate
This is a bitmask type.
bool uncaught_exception() noexcept
ISO C++ entities toplevel namespace is std.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
virtual ~basic_ostream()
Base destructor.
__ostream_type & write(const char_type *__s, streamsize __n)
Character string insertion.
static const iostate goodbit
Indicates all is well.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
pos_type tellp()
Getting the current write position.
__ostream_type & put(char_type __c)
Simple insertion.
Performs setup work for output streams.
__ostream_type & operator<<(__ostream_type &(*__pf)(__ostream_type &))
Interface for manipulators.
_Ios_Seekdir seekdir
This is an enumerated type.
static const iostate badbit
Indicates a loss of integrity in an input or output sequence (such as an irrecoverable read error fro...