namespace std {
template <class charT, class traits = char_traits<charT>>
class basic_ostream<charT, traits>::sentry {
bool ok_; // exposition only
public:
explicit sentry(basic_ostream<charT, traits>& os);
~sentry();
explicit operator bool() const { return ok_; }
sentry(const sentry&) = delete;
sentry& operator=(const sentry&) = delete;
};
}
The class sentry defines a class that is responsible for doing exception safe prefix and suffix operations.
explicit sentry(basic_ostream<charT, traits>& os);
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]))319
~sentry();
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;
The call os.tie()->flush() does not necessarily occur if the function can determine that no synchronization is necessary.
The sentry constructor and destructor can also perform additional implementation-dependent operations.