File Index Symbol Index

// ostream standard header
#pragma once
#ifndef _OSTREAM_
#define _OSTREAM_
#ifndef RC_INVOKED #include <ios>
_STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new
// I/O EXCEPTION MACROS
#if _HAS_EXCEPTIONS
#define _TRY_IO_BEGIN _TRY_BEGIN /* begin try block */
#define _CATCH_IO_END _CATCH_ALL /* catch block for _Myios */ \
_Myios::setstate(ios_base::badbit, true); /* set badbit and rethrow */ \
_CATCH_END
#define _CATCH_IO_(x) _CATCH_ALL /* catch block for basic_ios x */ \
(x).setstate(ios_base::badbit, true); /* set badbit and rethrow */ \
_CATCH_END
#else /* _HAS_EXCEPTIONS */
#define _TRY_IO_BEGIN { /* begin try block */
#define _CATCH_IO_END } /* catch block for _Myios */
#define _CATCH_IO_(x) } /* catch block for basic_ios x */ #endif /* _HAS_EXCEPTIONS */
// CLASS TEMPLATE basic_ostream
template
<
class
_Elem
,
class
_Traits
>
class
basic_ostream
:
virtual
public
basic_ios
<
_Elem
,
_Traits
> {
// control insertions into a stream buffer
public
:
typedef
basic_ios
<
_Elem
,
_Traits
>
_Myios
;
typedef
basic_streambuf
<
_Elem
,
_Traits
>
_Mysb
;
typedef
ostreambuf_iterator
<
_Elem
,
_Traits
>
_Iter
;
typedef
num_put
<
_Elem
,
_Iter
>
_Nput
;
basic_streambuf
<
_Elem
,
_Traits
> *
_Strbuf
,
bool
_Isstd
=
false
) {
// construct from a stream buffer pointer
_Myios
::
init
(
_Strbuf
,
_Isstd
); } {
// construct uninitialized
if
(
_Addit
)
this
->
_Addstd
(
this
);
// suppress for basic_iostream
}
protected
: {
// construct by moving _Right
_Myios
::
init
(); } {
// move from _Right
this
->
swap
(
_Right
);
return
(*
this
); } {
// swap with _Right
_Myios
::
swap
(
_Right
); }
public
: {
// destroy the object
}
typedef
typename
_Traits
::int_type
int_type
;
typedef
typename
_Traits
::pos_type
pos_type
;
typedef
typename
_Traits
::off_type
off_type
;
class
_Sentry_base
{
// stores thread lock and reference to output stream
public
: : _Myostr(
_Ostr
) {
// lock the stream buffer, if there
if
(
_Myostr
.
rdbuf
() !=
nullptr
)
_Myostr
.
rdbuf
()->_Lock(); } {
// destroy after unlocking
if
(
_Myostr
.
rdbuf
() !=
nullptr
)
_Myostr
.
rdbuf
()->_Unlock(); }
basic_ostream
&
_Myostr
;
// the output stream, for _Unlock call at destruction
_Sentry_base
&
operator
=
(
const
_Sentry_base
&) =
delete
; };
class
sentry
:
public
_Sentry_base
{
// stores thread lock and state of stream
public
: :
_Sentry_base
(
_Ostr
) {
// construct locking and testing stream
if
(
_Ostr
.
good
() &&
_Ostr
.
tie
() !=
nullptr
&&
_Ostr
.
tie
() != &
_Ostr
)
_Ostr
.
tie
()->flush();
_Ok
=
_Ostr
.
good
();
// store test only after flushing tie
}
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#else /* ^^^ clang ^^^ / vvv not clang vvv */
{
// destroy the object
#if _HAS_EXCEPTIONS
{
this
->
_Myostr
.
_Osfx
(); }
#else /* _HAS_EXCEPTIONS */
this->_Myostr._Osfx(); #endif /* _HAS_EXCEPTIONS */
}
#ifdef __clang__
#pragma clang diagnostic pop
#else /* ^^^ clang ^^^ / vvv not clang vvv */
{
// test if stream state okay
return
(
_Ok
); }
private
:
bool
_Ok
;
// true if stream state okay at construction
}; {
// test stream state and flush tie stream as needed (retained)
if
(
this
->
good
() &&
_Myios
::
tie
() !=
nullptr
&&
_Myios
::
tie
() !=
this
)
_Myios
::
tie
()->flush();
return
(
this
->
good
()); } {
// perform any wrapup (retained)
_Osfx
(); } {
// perform any wrapup
if
(
this
->
good
() &&
this
->
flags
() &
ios_base
::
unitbuf
)
if
(
_Myios
::
rdbuf
()->pubsync() == -
1
)
// flush stream as needed
_Myios
::
setstate
(
ios_base
::
badbit
); }
#ifdef _M_CEE_PURE
basic_ostream& __CLR_OR_THIS_CALL operator<<(basic_ostream& (__clrcall *_Pfn)(basic_ostream&))
{ // call basic_ostream manipulator
return ((*_Pfn)(*this));
}
basic_ostream& __CLR_OR_THIS_CALL operator<<(_Myios& (__clrcall *_Pfn)(_Myios&))
{ // call basic_ios manipulator
(*_Pfn)(*(_Myios *)this);
return (*this);
}
basic_ostream& __CLR_OR_THIS_CALL operator<<(ios_base& (__clrcall *_Pfn)(ios_base&))
{ // call ios_base manipulator
(*_Pfn)(*(ios_base *)this);
return (*this);
}
#endif /* _M_CEE_PURE */
{
// call basic_ostream manipulator
return
((*
_Pfn
)(*
this
)); } {
// call basic_ios manipulator
(*
_Pfn
)(*(
_Myios
*)
this
);
return
(*
this
); } {
// call ios_base manipulator
(*
_Pfn
)(*(
ios_base
*)
this
);
return
(*
this
); } {
// insert a boolean
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
const
sentry
_Ok
(*
this
);
if
(
_Ok
) {
// state okay, use facet to insert
if
(
_Nput_fac
.
put
(
_Iter
(
_Myios
::
rdbuf
()), *
this
,
_Myios
::
fill
(),
_Val
).failed())
_State
|=
ios_base
::
badbit
; }
_Myios
::
setstate
(
_State
);
return
(*
this
); } {
// insert a short
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
const
sentry
_Ok
(*
this
);
if
(
_Ok
) {
// state okay, use facet to insert
ios_base
::
fmtflags
_Bfl
=
this
->
flags
() &
ios_base
::
basefield
;
long
_Tmp
= (
_Bfl
=
=
ios_base
::
oct
||
_Bfl
=
=
ios_base
::
hex
) ? (
long
)(
unsigned
short
)
_Val
: (
long
)
_Val
;
if
(
_Nput_fac
.
put
(
_Iter
(
_Myios
::
rdbuf
()), *
this
,
_Myios
::
fill
(),
_Tmp
).failed())
_State
|=
ios_base
::
badbit
; }
_Myios
::
setstate
(
_State
);
return
(*
this
); }
/* NOTE: If you are not using native wchar_t, the unsigned short inserter is masked by an explicit specialization that treats an unsigned short as a wide character. To read or write unsigned shorts as integers with wchar_t streams, make wchar_t a native type with the command line option /Zc:wchar_t. */
{
// insert an unsigned short
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
const
sentry
_Ok
(*
this
);
if
(
_Ok
) {
// state okay, use facet to insert
if
(
_Nput_fac
.
put
(
_Iter
(
_Myios
::
rdbuf
()), *
this
,
_Myios
::
fill
(), (
unsigned
long
)
_Val
).failed())
_State
|=
ios_base
::
badbit
; }
_Myios
::
setstate
(
_State
);
return
(*
this
); } {
// insert an int
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
const
sentry
_Ok
(*
this
);
if
(
_Ok
) {
// state okay, use facet to insert
ios_base
::
fmtflags
_Bfl
=
this
->
flags
() &
ios_base
::
basefield
;
long
_Tmp
= (
_Bfl
=
=
ios_base
::
oct
||
_Bfl
=
=
ios_base
::
hex
) ? (
long
)(
unsigned
int
)
_Val
: (
long
)
_Val
;
if
(
_Nput_fac
.
put
(
_Iter
(
_Myios
::
rdbuf
()), *
this
,
_Myios
::
fill
(),
_Tmp
).failed())
_State
|=
ios_base
::
badbit
; }
_Myios
::
setstate
(
_State
);
return
(*
this
); } {
// insert an unsigned int
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
const
sentry
_Ok
(*
this
);
if
(
_Ok
) {
// state okay, use facet to insert
if
(
_Nput_fac
.
put
(
_Iter
(
_Myios
::
rdbuf
()), *
this
,
_Myios
::
fill
(), (
unsigned
long
)
_Val
).failed())
_State
|=
ios_base
::
badbit
; }
_Myios
::
setstate
(
_State
);
return
(*
this
); } {
// insert a long
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
const
sentry
_Ok
(*
this
);
if
(
_Ok
) {
// state okay, use facet to insert
if
(
_Nput_fac
.
put
(
_Iter
(
_Myios
::
rdbuf
()), *
this
,
_Myios
::
fill
(),
_Val
).failed())
_State
|=
ios_base
::
badbit
; }
_Myios
::
setstate
(
_State
);
return
(*
this
); } {
// insert an unsigned long
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
const
sentry
_Ok
(*
this
);
if
(
_Ok
) {
// state okay, use facet to insert
if
(
_Nput_fac
.
put
(
_Iter
(
_Myios
::
rdbuf
()), *
this
,
_Myios
::
fill
(),
_Val
).failed())
_State
|=
ios_base
::
badbit
; }
_Myios
::
setstate
(
_State
);
return
(*
this
); } {
// insert a long long
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
const
sentry
_Ok
(*
this
);
if
(
_Ok
) {
// state okay, use facet to insert
if
(
_Nput_fac
.
put
(
_Iter
(
_Myios
::
rdbuf
()), *
this
,
_Myios
::
fill
(),
_Val
).failed())
_State
|=
ios_base
::
badbit
; }
_Myios
::
setstate
(
_State
);
return
(*
this
); } {
// insert an unsigned long long
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
const
sentry
_Ok
(*
this
);
if
(
_Ok
) {
// state okay, use facet to insert
if
(
_Nput_fac
.
put
(
_Iter
(
_Myios
::
rdbuf
()), *
this
,
_Myios
::
fill
(),
_Val
).failed())
_State
|=
ios_base
::
badbit
; }
_Myios
::
setstate
(
_State
);
return
(*
this
); } {
// insert a float
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
const
sentry
_Ok
(*
this
);
if
(
_Ok
) {
// state okay, use facet to insert
if
(
_Nput_fac
.
put
(
_Iter
(
_Myios
::
rdbuf
()), *
this
,
_Myios
::
fill
(), (
double
)
_Val
).failed())
_State
|=
ios_base
::
badbit
; }
_Myios
::
setstate
(
_State
);
return
(*
this
); } {
// insert a double
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
const
sentry
_Ok
(*
this
);
if
(
_Ok
) {
// state okay, use facet to insert
if
(
_Nput_fac
.
put
(
_Iter
(
_Myios
::
rdbuf
()), *
this
,
_Myios
::
fill
(),
_Val
).failed())
_State
|=
ios_base
::
badbit
; }
_Myios
::
setstate
(
_State
);
return
(*
this
); } {
// insert a long double
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
const
sentry
_Ok
(*
this
);
if
(
_Ok
) {
// state okay, use facet to insert
if
(
_Nput_fac
.
put
(
_Iter
(
_Myios
::
rdbuf
()), *
this
,
_Myios
::
fill
(),
_Val
).failed())
_State
|=
ios_base
::
badbit
; }
_Myios
::
setstate
(
_State
);
return
(*
this
); } {
// insert a void pointer
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
const
sentry
_Ok
(*
this
);
if
(
_Ok
) {
// state okay, use facet to insert
if
(
_Nput_fac
.
put
(
_Iter
(
_Myios
::
rdbuf
()), *
this
,
_Myios
::
fill
(),
_Val
).failed())
_State
|=
ios_base
::
badbit
; }
_Myios
::
setstate
(
_State
);
return
(*
this
); }
#if _HAS_CXX17 // LWG 2221 "No formatted output operator for nullptr"
template<class = void> // TRANSITION, ABI
basic_ostream& operator<<(nullptr_t)
{ // insert a null pointer
return (*this << "nullptr");
} #endif // _HAS_CXX17
{
// insert until end-of-file from a stream buffer
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
bool
_Copied
=
false
;
const
sentry
_Ok
(*
this
);
if
(
_Ok
&&
_Strbuf
!=
nullptr
)
for
(
int_type
_Meta
=
_Traits
::eof(); ;
_Copied
=
true
) {
// extract another character from stream buffer
_Meta
=
_Traits
::eq_int_type(
_Traits
::eof(),
_Meta
) ?
_Strbuf
->
sgetc
() :
_Strbuf
->
snextc
();
_Myios
::
setstate
(
ios_base
::
failbit
);
if
(
_Traits
::eq_int_type(
_Traits
::eof(),
_Meta
))
break
;
// end of file, quit
if
(
_Traits
::eq_int_type(
_Traits
::eof(),
_Myios
::
rdbuf
()->sputc(
_Traits
::to_char_type(
_Meta
)))) {
// insertion failed, quit
_State
|=
ios_base
::
badbit
;
break
; } }
this
->
width
(
0
);
_Myios
::
setstate
(
_Strbuf
==
nullptr
?
ios_base
::
badbit
: !
_Copied
?
_State
|
ios_base
::
failbit
:
_State
);
return
(*
this
); } {
// insert a character
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
const
sentry
_Ok
(*
this
);
if
(!
_Ok
)
_State
|=
ios_base
::
badbit
;
else
{
// state okay, insert character
if
(
_Traits
::eq_int_type(
_Traits
::eof(),
_Myios
::
rdbuf
()->sputc(
_Ch
)))
_State
|=
ios_base
::
badbit
; }
_Myios
::
setstate
(
_State
);
return
(*
this
); }
streamsize
_Count
) {
// insert _Count characters from array _Str
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
const
sentry
_Ok
(*
this
);
if
(!
_Ok
)
_State
|=
ios_base
::
badbit
;
else
if
(
0
<
_Count
) {
// state okay, insert characters
if
(
_Myios
::
rdbuf
()->sputn(
_Str
,
_Count
) !=
_Count
)
_State
|=
ios_base
::
badbit
; }
_Myios
::
setstate
(
_State
);
return
(*
this
); } {
// flush output stream
if
(
_Myios
::
rdbuf
() !=
nullptr
) {
// buffer exists, flush it
const
sentry
_Ok
(*
this
);
if
(
_Ok
&&
_Myios
::
rdbuf
()->pubsync() == -
1
)
_Myios
::
setstate
(
ios_base
::
badbit
);
// sync failed
}
return
(*
this
); } {
// set output stream position to _Pos
const
sentry
_Ok
(*
this
);
if
(!
this
->
fail
() && (
off_type
)
_Myios
::
rdbuf
()->pubseekpos(
_Pos
,
ios_base
::
out
) == -
1
)
_Myios
::
setstate
(
ios_base
::
failbit
);
return
(*
this
); } {
// change output stream position by _Off, according to _Way
const
sentry
_Ok
(*
this
);
if
(!
this
->
fail
() && (
off_type
)
_Myios
::
rdbuf
()->pubseekoff(
_Off
,
_Way
,
ios_base
::
out
) == -
1
)
_Myios
::
setstate
(
ios_base
::
failbit
);
return
(*
this
); } {
// return output stream position
const
sentry
_Ok
(*
this
);
if
(!
this
->
fail
())
return
(
_Myios
::
rdbuf
()->pubseekoff(
0
,
ios_base
::
cur
,
ios_base
::
out
));
else
return
(
pos_type
(-
1
)); } };
#ifndef _NATIVE_WCHAR_T_DEFINED
/* NOTE:
If you are not using native wchar_t, the following explicit
specialization will mask the member function (above) that treats
an unsigned short as an integer.
To read or write unsigned shorts as integers with wchar_t streams,
make wchar_t a native type with the command line option /Zc:wchar_t.
*/
template<> inline
basic_ostream<unsigned short, char_traits<unsigned short> >&
__CLR_OR_THIS_CALL basic_ostream<unsigned short,
char_traits<unsigned short> >::operator<<(unsigned short _Ch)
{ // extract a character
typedef char_traits<unsigned short> _Traits;
ios_base::iostate _State = ios_base::goodbit;
const sentry _Ok(*this);
if (_Ok)
{ // state okay, insert
streamsize _Pad = this->width() <= 1 ? 0 : this->width() - 1;
_TRY_IO_BEGIN
if ((this->flags() & ios_base::adjustfield) != ios_base::left)
for (; _State == ios_base::goodbit && 0 < _Pad;
--_Pad) // pad on left
if (_Traits::eq_int_type(_Traits::eof(),
this->rdbuf()->sputc(this->fill())))
_State |= ios_base::badbit;
if (_State == ios_base::goodbit
&& _Traits::eq_int_type(_Traits::eof(),
this->rdbuf()->sputc(_Ch)))
_State |= ios_base::badbit;
for (; _State == ios_base::goodbit && 0 < _Pad;
--_Pad) // pad on right
if (_Traits::eq_int_type(_Traits::eof(),
this->rdbuf()->sputc(this->fill())))
_State |= ios_base::badbit;
_CATCH_IO_END
}
this->width(0);
_Myios::setstate(_State);
return (*this);
}
#endif /* _NATIVE_WCHAR_T_DEFINED */
#if defined(_DLL_CPPLIB)
#if !defined(_CRTBLD) || defined(__FORCE_INSTANCE)
char_traits
<
char
> >;
char_traits
<
wchar_t
> >;
#endif /* !defined(_CRTBLD) || defined(__FORCE_INSTANCE) */
#ifdef __FORCE_INSTANCE
template class _CRTIMP2_PURE_IMPORT basic_ostream<unsigned short,
char_traits<unsigned short> >;
#endif /* __FORCE_INSTANCE */ #endif /* defined(_DLL_CPPLIB) */
// INSERTERS
template
<
class
_Elem
,
class
_Traits
>
inline
basic_ostream
<
_Elem
,
_Traits
>&
operator
<
<
(
basic_ostream
<
_Elem
,
_Traits
>&
_Ostr
,
const
char
*
_Val
) {
// insert NTBS
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
streamsize
_Pad
=
_Ostr
.
width
() <=
0
||
_Ostr
.
width
() <=
_Count
?
0
:
_Ostr
.
width
() -
_Count
;
const
typename
basic_ostream
<
_Elem
,
_Traits
>::
sentry
_Ok
(
_Ostr
);
if
(!
_Ok
)
_State
|=
ios_base
::
badbit
;
else
{
// state okay, insert characters
if
((
_Ostr
.
flags
() &
ios_base
::
adjustfield
) !=
ios_base
::
left
)
for
(;
0
<
_Pad
; --
_Pad
)
// pad on left
if
(
_Traits
::eq_int_type(
_Traits
::eof(),
_Ostr
.
rdbuf
()->sputc(
_Ostr
.
fill
()))) {
// insertion failed, quit
_State
|=
ios_base
::
badbit
;
break
; }
for
(;
_State
=
=
ios_base
::
goodbit
&&
0
<
_Count
; --
_Count
, ++
_Val
)
if
(
_Traits
::eq_int_type(
_Traits
::eof(),
_Ostr
.
rdbuf
()->sputc(
_Ctype_fac
.
widen
(*
_Val
))))
_State
|=
ios_base
::
badbit
;
if
(
_State
=
=
ios_base
::
goodbit
)
for
(;
0
<
_Pad
; --
_Pad
)
// pad on right
if
(
_Traits
::eq_int_type(
_Traits
::eof(),
_Ostr
.
rdbuf
()->sputc(
_Ostr
.
fill
()))) {
// insertion failed, quit
_State
|=
ios_base
::
badbit
;
break
; }
_Ostr
.
width
(
0
); }
_Ostr
.
setstate
(
_State
);
return
(
_Ostr
); }
template
<
class
_Elem
,
class
_Traits
>
inline
basic_ostream
<
_Elem
,
_Traits
>&
operator
<
<
(
basic_ostream
<
_Elem
,
_Traits
>&
_Ostr
,
char
_Ch
) {
// insert a character
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
const
typename
basic_ostream
<
_Elem
,
_Traits
>::
sentry
_Ok
(
_Ostr
);
if
(
_Ok
) {
// state okay, insert
streamsize
_Pad
=
_Ostr
.
width
() <=
1
?
0
:
_Ostr
.
width
() -
1
;
if
((
_Ostr
.
flags
() &
ios_base
::
adjustfield
) !=
ios_base
::
left
)
for
(;
_State
=
=
ios_base
::
goodbit
&&
0
<
_Pad
; --
_Pad
)
// pad on left
if
(
_Traits
::eq_int_type(
_Traits
::eof(),
_Ostr
.
rdbuf
()->sputc(
_Ostr
.
fill
())))
_State
|=
ios_base
::
badbit
;
if
(
_State
=
=
ios_base
::
goodbit
&&
_Traits
::eq_int_type(
_Traits
::eof(),
_Ostr
.
rdbuf
()->sputc(
_Ctype_fac
.
widen
(
_Ch
))))
_State
|=
ios_base
::
badbit
;
for
(;
_State
=
=
ios_base
::
goodbit
&&
0
<
_Pad
; --
_Pad
)
// pad on right
if
(
_Traits
::eq_int_type(
_Traits
::eof(),
_Ostr
.
rdbuf
()->sputc(
_Ostr
.
fill
())))
_State
|=
ios_base
::
badbit
; }
_Ostr
.
width
(
0
);
_Ostr
.
setstate
(
_State
);
return
(
_Ostr
); }
template
<
class
_Traits
>
inline
basic_ostream
<
char
,
_Traits
>&
operator
<
<
(
basic_ostream
<
char
,
_Traits
>&
_Ostr
,
const
char
*
_Val
) {
// insert NTBS into char stream
typedef
char
_Elem
;
typedef
basic_ostream
<
_Elem
,
_Traits
>
_Myos
;
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
streamsize
_Count
= (
streamsize
)
_Traits
::length(
_Val
);
// may overflow
streamsize
_Pad
=
_Ostr
.
width
() <=
0
||
_Ostr
.
width
() <=
_Count
?
0
:
_Ostr
.
width
() -
_Count
;
const
typename
_Myos
::
sentry
_Ok
(
_Ostr
);
if
(!
_Ok
)
_State
|=
ios_base
::
badbit
;
else
{
// state okay, insert
if
((
_Ostr
.
flags
() &
ios_base
::
adjustfield
) !=
ios_base
::
left
)
for
(;
0
<
_Pad
; --
_Pad
)
// pad on left
if
(
_Traits
::eq_int_type(
_Traits
::eof(),
_Ostr
.
rdbuf
()->sputc(
_Ostr
.
fill
()))) {
// insertion failed, quit
_State
|=
ios_base
::
badbit
;
break
; }
if
(
_State
=
=
ios_base
::
goodbit
&&
_Ostr
.
rdbuf
()->sputn(
_Val
,
_Count
) !=
_Count
)
_State
|=
ios_base
::
badbit
;
if
(
_State
=
=
ios_base
::
goodbit
)
for
(;
0
<
_Pad
; --
_Pad
)
// pad on right
if
(
_Traits
::eq_int_type(
_Traits
::eof(),
_Ostr
.
rdbuf
()->sputc(
_Ostr
.
fill
()))) {
// insertion failed, quit
_State
|=
ios_base
::
badbit
;
break
; }
_Ostr
.
width
(
0
); }
_Ostr
.
setstate
(
_State
);
return
(
_Ostr
); }
template
<
class
_Traits
>
inline
basic_ostream
<
char
,
_Traits
>&
operator
<
<
(
basic_ostream
<
char
,
_Traits
>&
_Ostr
,
char
_Ch
) {
// insert a char into char stream
typedef
char
_Elem
;
typedef
basic_ostream
<
_Elem
,
_Traits
>
_Myos
;
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
const
typename
_Myos
::
sentry
_Ok
(
_Ostr
);
if
(
_Ok
) {
// state okay, insert
streamsize
_Pad
=
_Ostr
.
width
() <=
1
?
0
:
_Ostr
.
width
() -
1
;
if
((
_Ostr
.
flags
() &
ios_base
::
adjustfield
) !=
ios_base
::
left
)
for
(;
_State
=
=
ios_base
::
goodbit
&&
0
<
_Pad
; --
_Pad
)
// pad on left
if
(
_Traits
::eq_int_type(
_Traits
::eof(),
_Ostr
.
rdbuf
()->sputc(
_Ostr
.
fill
())))
_State
|=
ios_base
::
badbit
;
if
(
_State
=
=
ios_base
::
goodbit
&&
_Traits
::eq_int_type(
_Traits
::eof(),
_Ostr
.
rdbuf
()->sputc(
_Ch
)))
_State
|=
ios_base
::
badbit
;
for
(;
_State
=
=
ios_base
::
goodbit
&&
0
<
_Pad
; --
_Pad
)
// pad on right
if
(
_Traits
::eq_int_type(
_Traits
::eof(),
_Ostr
.
rdbuf
()->sputc(
_Ostr
.
fill
())))
_State
|=
ios_base
::
badbit
; }
_Ostr
.
width
(
0
);
_Ostr
.
setstate
(
_State
);
return
(
_Ostr
); }
template
<
class
_Elem
,
class
_Traits
>
inline
basic_ostream
<
_Elem
,
_Traits
>&
operator
<
<
(
basic_ostream
<
_Elem
,
_Traits
>&
_Ostr
,
const
_Elem
*
_Val
) {
// insert NTCS
typedef
basic_ostream
<
_Elem
,
_Traits
>
_Myos
;
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
streamsize
_Count
= (
streamsize
)
_Traits
::length(
_Val
);
// may overflow
streamsize
_Pad
=
_Ostr
.
width
() <=
0
||
_Ostr
.
width
() <=
_Count
?
0
:
_Ostr
.
width
() -
_Count
;
const
typename
_Myos
::
sentry
_Ok
(
_Ostr
);
if
(!
_Ok
)
_State
|=
ios_base
::
badbit
;
else
{
// state okay, insert
if
((
_Ostr
.
flags
() &
ios_base
::
adjustfield
) !=
ios_base
::
left
)
for
(;
0
<
_Pad
; --
_Pad
)
// pad on left
if
(
_Traits
::eq_int_type(
_Traits
::eof(),
_Ostr
.
rdbuf
()->sputc(
_Ostr
.
fill
()))) {
// insertion failed, quit
_State
|=
ios_base
::
badbit
;
break
; }
if
(
_State
=
=
ios_base
::
goodbit
&&
_Ostr
.
rdbuf
()->sputn(
_Val
,
_Count
) !=
_Count
)
_State
|=
ios_base
::
badbit
;
if
(
_State
=
=
ios_base
::
goodbit
)
for
(;
0
<
_Pad
; --
_Pad
)
// pad on right
if
(
_Traits
::eq_int_type(
_Traits
::eof(),
_Ostr
.
rdbuf
()->sputc(
_Ostr
.
fill
()))) {
// insertion failed, quit
_State
|=
ios_base
::
badbit
;
break
; }
_Ostr
.
width
(
0
); }
_Ostr
.
setstate
(
_State
);
return
(
_Ostr
); }
template
<
class
_Elem
,
class
_Traits
>
inline
basic_ostream
<
_Elem
,
_Traits
>&
operator
<
<
(
basic_ostream
<
_Elem
,
_Traits
>&
_Ostr
,
_Elem
_Ch
) {
// insert a character
typedef
basic_ostream
<
_Elem
,
_Traits
>
_Myos
;
ios_base
::
iostate
_State
=
ios_base
::
goodbit
;
const
typename
_Myos
::
sentry
_Ok
(
_Ostr
);
if
(
_Ok
) {
// state okay, insert
streamsize
_Pad
=
_Ostr
.
width
() <=
1
?
0
:
_Ostr
.
width
() -
1
;
if
((
_Ostr
.
flags
() &
ios_base
::
adjustfield
) !=
ios_base
::
left
)
for
(;
_State
=
=
ios_base
::
goodbit
&&
0
<
_Pad
; --
_Pad
)
// pad on left
if
(
_Traits
::eq_int_type(
_Traits
::eof(),
_Ostr
.
rdbuf
()->sputc(
_Ostr
.
fill
())))
_State
|=
ios_base
::
badbit
;
if
(
_State
=
=
ios_base
::
goodbit
&&
_Traits
::eq_int_type(
_Traits
::eof(),
_Ostr
.
rdbuf
()->sputc(
_Ch
)))
_State
|=
ios_base
::
badbit
;
for
(;
_State
=
=
ios_base
::
goodbit
&&
0
<
_Pad
; --
_Pad
)
// pad on right
if
(
_Traits
::eq_int_type(
_Traits
::eof(),
_Ostr
.
rdbuf
()->sputc(
_Ostr
.
fill
())))
_State
|=
ios_base
::
badbit
; }
_Ostr
.
width
(
0
);
_Ostr
.
setstate
(
_State
);
return
(
_Ostr
); }
template
<
class
_Traits
>
inline
basic_ostream
<
char
,
_Traits
>&
operator
<
<
(
basic_ostream
<
char
,
_Traits
>&
_Ostr
,
const
signed
char
*
_Val
) {
// insert a signed char NTBS
return
(
_Ostr
<
<
(
const
char
*)
_Val
); }
template
<
class
_Traits
>
inline
basic_ostream
<
char
,
_Traits
>&
operator
<
<
(
basic_ostream
<
char
,
_Traits
>&
_Ostr
,
signed
char
_Ch
) {
// insert a signed char
return
(
_Ostr
<
<
(
char
)
_Ch
); }
template
<
class
_Traits
>
inline
basic_ostream
<
char
,
_Traits
>&
operator
<
<
(
basic_ostream
<
char
,
_Traits
>&
_Ostr
,
const
unsigned
char
*
_Val
) {
// insert an unsigned char NTBS
return
(
_Ostr
<
<
(
const
char
*)
_Val
); }
template
<
class
_Traits
>
inline
basic_ostream
<
char
,
_Traits
>&
operator
<
<
(
basic_ostream
<
char
,
_Traits
>&
_Ostr
,
unsigned
char
_Ch
) {
// insert an unsigned char
return
(
_Ostr
<
<
(
char
)
_Ch
); }
template
<
class
_Ostr
,
class
_Ty
,
class
=
void
>
struct
_Can_stream_out
:
false_type
{ };
template
<
class
_Ostr
,
class
_Ty
> :
true_type
{ };
template
<
class
_Ostr
,
class
_Ty
,
enable_if_t
<
conjunction_v
<
// prevent infinite recursion
negation
<
is_lvalue_reference
<
_Ostr
>>,
is_base_of
<
ios_base
,
_Ostr
>,
_Can_stream_out
<
_Ostr
,
_Ty
>>,
int
> =
0
>
inline
_Ostr
&&
operator
<
<
(
_Ostr
&&
_Os
,
const
_Ty
&
_Val
) {
// insert to rvalue stream
_Os
<<
_Val
; }
// MANIPULATORS
template
<
class
_Elem
,
class
_Traits
>
inline
basic_ostream
<
_Elem
,
_Traits
>& {
// insert newline and flush stream
_Ostr
.
put
(
_Ostr
.
widen
(
'\n'
));
_Ostr
.
flush
();
return
(
_Ostr
); }
template
<
class
_Elem
,
class
_Traits
>
inline
basic_ostream
<
_Elem
,
_Traits
>& {
// insert null character
_Ostr
.
put
(
_Elem
());
return
(
_Ostr
); }
template
<
class
_Elem
,
class
_Traits
>
inline
basic_ostream
<
_Elem
,
_Traits
>& {
// flush stream
_Ostr
.
flush
();
return
(
_Ostr
); }
// INSERTER FOR error_category
template
<
class
_Elem
,
class
_Traits
>
inline
basic_ostream
<
_Elem
,
_Traits
>&
operator
<
<
(
basic_ostream
<
_Elem
,
_Traits
>&
_Ostr
,
const
error_code
&
_Errcode
) {
// display error code
return
(
_Ostr
<
<
_Errcode
.
category
().
name
()
<
<
':'
<
<
_Errcode
.
value
()); }
#pragma pop_macro("new")
_STL_RESTORE_CLANG_WARNINGS
/* * Copyright (c) by P.J. Plauger. All rights reserved. * Consult your license regarding permissions and restrictions. V6.50:0009 */