STD::BASIC_OSTREAM_SENTRY(3)
π std::basic_ostream< _CharT, _Traits >::sentry β Library Functions Manual π
okay bestie, we're reading the Library Functions Manual page for std::basic_ostream< _CharT, _Traits >::sentry and honestly? it's giving backstage crew energy. nobody claps for it, but the whole show falls apart without it. π
β¨ NAME β¨
std::basic_ostream< _CharT, _Traits >::sentry β Performs setup work for output streams.
like... it literally says it in the name. setup. work. for output streams. the pregame before the pregame. π
β¨ SYNOPSIS β¨
#include <ostream>
πΈ Public Member Functions πΈ
sentry (basic_ostream< _CharT, _Traits > &__os)β The constructor performs preparatory work.~sentry ()β Possibly flushes the stream.operator bool () constβ Quick status checking.
β¨ Detailed Description β¨
template<typename _CharT, typename _Traits>
class std::basic_ostream< _CharT, _Traits >::sentry
"Performs setup work for output streams.
Objects of this class are created before all of the standard inserters are run. It is responsible for exception-safe prefix and suffix operations."
so real talk: every time you << something, a little sentry object gets built first. it does the exception-safe prefix stuff on the way in and the suffix stuff on the way out. it's the bodyguard standing at the door of your output stream, checking vibes before anyone gets in. π«Ά
β¨ Constructor & Destructor Documentation β¨
π sentry π
template<typename _CharT, typename _Traits> std::basic_ostream< _CharT,
_Traits >::sentry::sentry (basic_ostream< _CharT, _Traits > & __os)
[explicit]
The constructor performs preparatory work.
Parameters
__osβ The output stream to guard.
so here's the tea, step by step:
If the stream state is good (__os.good() is true), then if the stream is tied to another output stream, is.tie()->flush() is called to synchronize the output sequences.
If the stream state is still good, then the sentry state becomes true (okay).
References std::basic_ostream< _CharT, _Traits >::basic_ostream(), std::basic_ios< _CharT, _Traits >::bad(), std::ios_base::failbit, std::basic_ios< _CharT, _Traits >::good(), std::basic_ios< _CharT, _Traits >::setstate(), and std::basic_ios< _CharT, _Traits >::tie().
π ~sentry π
template<typename _CharT, typename _Traits> std::basic_ostream< _CharT,
_Traits >::sentry::~sentry () [inline]
Possibly flushes the stream. If ios_base::unitbuf is set in os.flags(), and std::uncaught_exception() is true, the sentry destructor flushes the output stream.
notice the word possibly up there. this destructor is not out here flushing on every single goodbye, bestie. only under those exact conditions. no cap.
References std::ios_base::badbit, std::uncaught_exception(), and std::ios_base::unitbuf.
β¨ Member Function Documentation β¨
π¦ operator bool π¦
template<typename _CharT, typename _Traits> std::basic_ostream< _CharT,
_Traits >::sentry::operator bool () const [inline], [explicit]
Quick status checking.
Returns
- The sentry state.
For ease of use, sentries may be converted to booleans. The return value is that of the sentry state (true == okay).
okay so this is the little vibe check. you can drop a sentry straight into a boolean context and it'll tell you if everything's good. true means okay. iconic behavior honestly. β
β¨ Author β¨
Generated automatically by Doxygen for libstdc++ from the source code.
and that's the whole page, bestie!! π this one came straight from libstdc++ (generated by Doxygen for libstdc++, from the source code, exactly as the manpage says) β so go forth and appreciate your little stream bodyguards, they're doing so much unpaid emotional labor for you. mwah. πππ¦β¨
π¦ where this page comes from
- arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
- fedora 43: libstdc++-docs 15.2.1-2.fc43 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- fedora 43: libstdc++-docs 15.3.1-1.fc43 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- fedora 44: libstdc++-docs 16.2.1-2.fc44
- fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms