33 #ifndef _GLIBCXX_OSTREAM
34 #define _GLIBCXX_OSTREAM 1
36 #pragma GCC system_header
41 namespace std _GLIBCXX_VISIBILITY(default)
43 _GLIBCXX_BEGIN_NAMESPACE_VERSION
57 template<
typename _CharT,
typename _Traits>
58 class basic_ostream :
virtual public basic_ios<_CharT, _Traits>
62 typedef _CharT char_type;
63 typedef typename _Traits::int_type int_type;
64 typedef typename _Traits::pos_type pos_type;
65 typedef typename _Traits::off_type off_type;
66 typedef _Traits traits_type;
69 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
70 typedef basic_ios<_CharT, _Traits> __ios_type;
71 typedef basic_ostream<_CharT, _Traits> __ostream_type;
72 typedef num_put<_CharT, ostreambuf_iterator<_CharT, _Traits> >
74 typedef ctype<_CharT> __ctype_type;
167 {
return _M_insert(__n); }
171 {
return _M_insert(__n); }
175 {
return _M_insert(__n); }
185 return _M_insert(static_cast<unsigned long>(__n));
196 return _M_insert(static_cast<unsigned long>(__n));
199 #ifdef _GLIBCXX_USE_LONG_LONG
202 {
return _M_insert(__n); }
206 {
return _M_insert(__n); }
221 {
return _M_insert(__f); }
228 return _M_insert(static_cast<double>(__f));
233 {
return _M_insert(__f); }
246 {
return _M_insert(__p); }
248 #if __cplusplus >= 201703L
251 {
return *
this <<
"nullptr"; }
387 seekp(off_type, ios_base::seekdir);
393 #if __cplusplus >= 201103L
395 basic_ostream(basic_iostream<_CharT, _Traits>&) { }
415 swap(basic_ostream& __rhs)
416 { __ios_type::swap(__rhs); }
419 template<
typename _ValueT>
421 _M_insert(_ValueT __v);
431 template <
typename _CharT,
typename _Traits>
453 #pragma GCC diagnostic push
454 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
468 if (_M_os.rdbuf() && _M_os.rdbuf()->pubsync() == -1)
472 #pragma GCC diagnostic pop
481 #if __cplusplus >= 201103L
484 operator bool()
const
504 template<
typename _CharT,
typename _Traits>
506 operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
507 {
return __ostream_insert(__out, &__c, 1); }
509 template<
typename _CharT,
typename _Traits>
510 inline basic_ostream<_CharT, _Traits>&
511 operator<<(basic_ostream<_CharT, _Traits>& __out,
char __c)
512 {
return (__out << __out.widen(__c)); }
515 template<
typename _Traits>
516 inline basic_ostream<char, _Traits>&
517 operator<<(basic_ostream<char, _Traits>& __out,
char __c)
518 {
return __ostream_insert(__out, &__c, 1); }
521 template<
typename _Traits>
522 inline basic_ostream<char, _Traits>&
523 operator<<(basic_ostream<char, _Traits>& __out,
signed char __c)
524 {
return (__out << static_cast<char>(__c)); }
526 template<
typename _Traits>
527 inline basic_ostream<char, _Traits>&
528 operator<<(basic_ostream<char, _Traits>& __out,
unsigned char __c)
529 {
return (__out << static_cast<char>(__c)); }
531 #if __cplusplus > 201703L
535 #ifdef _GLIBCXX_USE_WCHAR_T
536 template<
typename _Traits>
537 basic_ostream<char, _Traits>&
538 operator<<(basic_ostream<char, _Traits>&, wchar_t) =
delete;
539 #endif // _GLIBCXX_USE_WCHAR_T
541 #ifdef _GLIBCXX_USE_CHAR8_T
542 template<
typename _Traits>
543 basic_ostream<char, _Traits>&
544 operator<<(basic_ostream<char, _Traits>&, char8_t) =
delete;
547 template<
typename _Traits>
548 basic_ostream<char, _Traits>&
549 operator<<(basic_ostream<char, _Traits>&, char16_t) =
delete;
551 template<
typename _Traits>
552 basic_ostream<char, _Traits>&
553 operator<<(basic_ostream<char, _Traits>&, char32_t) =
delete;
555 #ifdef _GLIBCXX_USE_WCHAR_T
556 #ifdef _GLIBCXX_USE_CHAR8_T
557 template<
typename _Traits>
558 basic_ostream<wchar_t, _Traits>&
559 operator<<(basic_ostream<wchar_t, _Traits>&, char8_t) =
delete;
560 #endif // _GLIBCXX_USE_CHAR8_T
562 template<
typename _Traits>
563 basic_ostream<wchar_t, _Traits>&
564 operator<<(basic_ostream<wchar_t, _Traits>&, char16_t) =
delete;
566 template<
typename _Traits>
567 basic_ostream<wchar_t, _Traits>&
568 operator<<(basic_ostream<wchar_t, _Traits>&, char32_t) =
delete;
569 #endif // _GLIBCXX_USE_WCHAR_T
587 template<
typename _CharT,
typename _Traits>
588 inline basic_ostream<_CharT, _Traits>&
589 operator<<(basic_ostream<_CharT, _Traits>& __out,
const _CharT* __s)
594 __ostream_insert(__out, __s,
595 static_cast<streamsize>(_Traits::length(__s)));
599 template<
typename _CharT,
typename _Traits>
600 basic_ostream<_CharT, _Traits> &
601 operator<<(basic_ostream<_CharT, _Traits>& __out,
const char* __s);
604 template<
typename _Traits>
605 inline basic_ostream<char, _Traits>&
606 operator<<(basic_ostream<char, _Traits>& __out,
const char* __s)
611 __ostream_insert(__out, __s,
612 static_cast<streamsize>(_Traits::length(__s)));
617 template<
typename _Traits>
618 inline basic_ostream<char, _Traits>&
619 operator<<(basic_ostream<char, _Traits>& __out,
const signed char* __s)
620 {
return (__out << reinterpret_cast<const char*>(__s)); }
622 template<
typename _Traits>
623 inline basic_ostream<char, _Traits> &
624 operator<<(basic_ostream<char, _Traits>& __out,
const unsigned char* __s)
625 {
return (__out << reinterpret_cast<const char*>(__s)); }
627 #if __cplusplus > 201703L
631 #ifdef _GLIBCXX_USE_WCHAR_T
632 template<
typename _Traits>
633 basic_ostream<char, _Traits>&
634 operator<<(basic_ostream<char, _Traits>&,
const wchar_t*) =
delete;
635 #endif // _GLIBCXX_USE_WCHAR_T
637 #ifdef _GLIBCXX_USE_CHAR8_T
638 template<
typename _Traits>
639 basic_ostream<char, _Traits>&
640 operator<<(basic_ostream<char, _Traits>&,
const char8_t*) =
delete;
641 #endif // _GLIBCXX_USE_CHAR8_T
643 template<
typename _Traits>
644 basic_ostream<char, _Traits>&
645 operator<<(basic_ostream<char, _Traits>&,
const char16_t*) =
delete;
647 template<
typename _Traits>
648 basic_ostream<char, _Traits>&
649 operator<<(basic_ostream<char, _Traits>&,
const char32_t*) =
delete;
651 #ifdef _GLIBCXX_USE_WCHAR_T
652 #ifdef _GLIBCXX_USE_CHAR8_T
653 template<
typename _Traits>
654 basic_ostream<wchar_t, _Traits>&
655 operator<<(basic_ostream<wchar_t, _Traits>&,
const char8_t*) =
delete;
658 template<
typename _Traits>
659 basic_ostream<wchar_t, _Traits>&
660 operator<<(basic_ostream<wchar_t, _Traits>&,
const char16_t*) =
delete;
662 template<
typename _Traits>
663 basic_ostream<wchar_t, _Traits>&
664 operator<<(basic_ostream<wchar_t, _Traits>&,
const char32_t*) =
delete;
665 #endif // _GLIBCXX_USE_WCHAR_T
679 template<
typename _CharT,
typename _Traits>
680 inline basic_ostream<_CharT, _Traits>&
682 {
return flush(__os.put(__os.widen(
'\n'))); }
691 template<
typename _CharT,
typename _Traits>
692 inline basic_ostream<_CharT, _Traits>&
694 {
return __os.put(_CharT()); }
701 template<
typename _CharT,
typename _Traits>
702 inline basic_ostream<_CharT, _Traits>&
704 {
return __os.flush(); }
706 #if __cplusplus >= 201103L
711 #if __cpp_lib_concepts
713 template<
typename _Tp>
714 concept __derived_from_ios_base = is_class_v<_Tp>
715 && (!is_same_v<_Tp, ios_base>)
716 && requires (_Tp* __t, ios_base* __b) { __b = __t; };
718 template<
typename _Os,
typename _Tp>
719 requires __derived_from_ios_base<_Os>
720 && requires (_Os& __os,
const _Tp& __t) { __os << __t; }
721 using __rvalue_stream_insertion_t = _Os&&;
723 template<
typename _Tp>
724 using _Require_derived_from_ios_base
725 = _Require<is_class<_Tp>, __not_<is_same<_Tp, ios_base>>,
726 is_convertible<typename add_pointer<_Tp>::type, ios_base*>>;
728 template<
typename _Os,
typename _Tp,
729 typename = _Require_derived_from_ios_base<_Os>,
731 = decltype(std::declval<_Os&>() << std::declval<const _Tp&>())>
732 using __rvalue_stream_insertion_t = _Os&&;
745 template<
typename _Ostream,
typename _Tp>
746 inline __rvalue_stream_insertion_t<_Ostream, _Tp>
753 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
754 template<
typename _CharT,
typename _Traits>
755 class __syncbuf_base :
public basic_streambuf<_CharT, _Traits>
759 _S_get(basic_streambuf<_CharT, _Traits>* __buf [[maybe_unused]]) noexcept
762 if (
auto __p = dynamic_cast<__syncbuf_base*>(__buf))
763 return &__p->_M_emit_on_sync;
769 __syncbuf_base(basic_streambuf<_CharT, _Traits>* __w =
nullptr)
773 basic_streambuf<_CharT, _Traits>* _M_wrapped =
nullptr;
774 bool _M_emit_on_sync =
false;
775 bool _M_needs_sync =
false;
778 template<
typename _CharT,
typename _Traits>
779 inline basic_ostream<_CharT, _Traits>&
780 emit_on_flush(basic_ostream<_CharT, _Traits>& __os)
782 if (
bool* __flag = __syncbuf_base<_CharT, _Traits>::_S_get(__os.rdbuf()))
787 template<
typename _CharT,
typename _Traits>
788 inline basic_ostream<_CharT, _Traits>&
789 noemit_on_flush(basic_ostream<_CharT, _Traits>& __os)
791 if (
bool* __flag = __syncbuf_base<_CharT, _Traits>::_S_get(__os.rdbuf()))
796 template<
typename _CharT,
typename _Traits>
797 inline basic_ostream<_CharT, _Traits>&
798 flush_emit(basic_ostream<_CharT, _Traits>& __os)
802 ~_Restore() { *_M_flag = _M_prev; }
804 bool _M_prev =
false;
805 bool* _M_flag = &_M_prev;
808 if (
bool* __flag = __syncbuf_base<_CharT, _Traits>::_S_get(__os.rdbuf()))
810 __restore._M_prev = *__flag;
811 __restore._M_flag = __flag;
823 _GLIBCXX_END_NAMESPACE_VERSION
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
void init(basic_streambuf< _CharT, _Traits > *__sb)
All setup is performed here.
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
Write a newline and flush the stream.
~sentry()
Possibly flushes the stream.
basic_streambuf< _CharT, _Traits > * rdbuf() const
Accessing the underlying buffer.
__ostream_type & write(const char_type *__s, streamsize __n)
Character string insertion.
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.
virtual ~basic_ostream()
Base destructor.
__ostream_type & operator<<(__ostream_type &(*__pf)(__ostream_type &))
Interface for manipulators.
static const fmtflags unitbuf
Flushes output after each output operation.
basic_ostream< _CharT, _Traits > & flush(basic_ostream< _CharT, _Traits > &__os)
Flushes the output stream.
bool uncaught_exception() noexcept
Performs setup work for output streams.
__ostream_type & seekp(pos_type)
Changing the current write position.
static const iostate badbit
Indicates a loss of integrity in an input or output sequence (such as an irrecoverable read error fro...
pos_type tellp()
Getting the current write position.
__ostream_type & put(char_type __c)
Simple insertion.
void _M_write(const char_type *__s, streamsize __n)
Core write functionality, without sentry.
void setstate(iostate __state)
Sets additional flags in the error state.
The base of the I/O class hierarchy.This class defines everything that can be defined about I/O that ...
basic_ostream(__streambuf_type *__sb)
Base constructor.
__ostream_type & flush()
Synchronizing the stream buffer.
auto_ptr & operator=(auto_ptr &__a)
auto_ptr assignment operator.