31
Input/output library
[input.output]
31.7
Formatting and manipulators
[iostream.format]
31.7.6
Output streams
[output.streams]
31.7.6.2
Class template
basic_
ostream
[ostream]
31.7.6.2.4
Class
basic_
ostream::sentry
[ostream.sentry]
🔗
namespace
std
{
template
<
class
charT,
class
traits
>
class
basic_ostream
<
charT, traits
>
::
sentry
{
bool
ok_;
//
exposition only
public
:
explicit
sentry
(
basic_ostream
&
os
)
;
~
sentry
(
)
;
explicit
operator
bool
(
)
const
{
return
ok_;
}
sentry
(
const
sentry
&
)
=
delete
; sentry
&
operator
=
(
const
sentry
&
)
=
delete
;
}
;
}
1
#
The class
sentry
defines a class that is responsible for doing exception safe prefix and suffix operations
.
🔗
explicit
sentry
(
basic_ostream
&
os
)
;
2
#
If
os
.
good
(
)
is nonzero, prepares for formatted or unformatted output
.
If
os
.
tie
(
)
is not a null pointer, calls
os
.
tie
(
)
-
>
flush
(
)
.
293
3
#
If, after any preparation is completed,
os
.
good
(
)
is
true
,
ok_
=
=
true
otherwise,
ok_
=
=
false
.
During preparation, the constructor may call
setstate
(
failbit
)
(which may throw
ios_
base
::
failure
(
[iostate.
flags]
))
.
294
🔗
~
sentry
(
)
;
4
#
If
(
os
.
flags
(
)
&
ios_
base
::
unitbuf
)
&
&
!
uncaught_
exceptions
(
)
&
&
os
.
good
(
)
is
true
, calls
os
.
rdbuf
(
)
-
>
pubsync
(
)
.
If that function returns
−
1
, sets
badbit
in
os
.
rdstate
(
)
without propagating an exception
.
🔗
explicit
operator
bool
(
)
const
;
5
#
Effects
: Returns
ok_
.
293)
293)
The call
os
.
tie
(
)
-
>
flush
(
)
does not necessarily occur if the function can determine that no synchronization is necessary
.
294)
294)
The
sentry
constructor and destructor can also perform additional
implementation-dependent operations
.