std::basic_osyncstream(3)
π NAME π
okay so bestie, you are looking at the std::basic_osyncstream(3) page from the C++ Standard Library, and the official name line is still exactly:
std::basic_osyncstream - std::basic_osyncstream
β¨ Synopsis β¨
Defined in header <syncstream>.
This whole synopsis is (since C++20).
template<
class CharT,
class Traits = std::char_traits<CharT>,
class Allocator = std::allocator<CharT>
> class basic_osyncstream : public std::basic_ostream<CharT, Traits>
The class template std::basic_osyncstream is a convenience wrapper for std::basic_syncbuf. It provides a mechanism to synchronize threads writing to the same stream. slay π
It can be used with a named variable:
{
std::osyncstream synced_out(std::cout); // synchronized wrapper for std::cout
synced_out << "Hello, ";
synced_out << "World!";
synced_out << std::endl; // flush is noted, but not yet performed
synced_out << "and more!\n";
} // characters are transferred and std::cout is flushed
as well as with a temporary:
std::osyncstream(std::cout) << "Hello, " << "World!" << '\n';
It provides the guarantee that all output made to the same final destination buffer (std::cout in the examples above) will be free of data races and will not be interleaved or garbled in any way, as long as every write to that final destination buffer is made through (possibly different) instances of std::basic_osyncstream. no cap, that is the whole point π«Ά
Typical implementation of std::basic_osyncstream holds only one member: the wrapped std::basic_syncbuf.
There is also an inheritance diagram in the source: std-basic osyncstream-inheritance.svg, labeled Inheritance diagram. iconic visual aid behavior π¦
Several typedefs for common character types are provided:
Defined in header <syncstream>.
std::osyncstreamβstd::basic_osyncstream<char>std::wosyncstreamβstd::basic_osyncstream<wchar_t>
𧬠Member types π§¬
char_typeβCharTtraits_typeβTraits; the program is ill-formed ifTraits::char_typeis notCharT. periodt, the compiler will absolutely clock that πint_typeβTraits::int_typepos_typeβTraits::pos_typeoff_typeβTraits::off_typeallocator_typeβAllocatorstreambuf_typeβstd::basic_streambuf<CharT, Traits>syncbuf_typeβstd::basic_syncbuf<CharT, Traits, Allocator>
π οΈ Member functions π οΈ
constructorβ constructs abasic_osyncstreamobject (public member function)operator=β assigns abasic_osyncstreamobject (public member function)destructorβ destroys thebasic_osyncstreamand emits its internal buffer (public member function)rdbufβ obtains a pointer to the underlyingbasic_syncbuf(public member function)get_wrappedβ obtains a pointer to the final destination stream buffer (public member function)emitβ callsemit()on the underlyingbasic_syncbufto transmit its internal data to the final destination (public member function)
π Inherited from std::basic_ostream π
Member functions
Formatted output
operator<<β inserts formatted data (public member function ofstd::basic_ostream<CharT,Traits>)
Unformatted output
putβ inserts a character (public member function ofstd::basic_ostream<CharT,Traits>)writeβ inserts blocks of characters (public member function ofstd::basic_ostream<CharT,Traits>)
Positioning
tellpβ returns the output position indicator (public member function ofstd::basic_ostream<CharT,Traits>)seekpβ sets the output position indicator (public member function ofstd::basic_ostream<CharT,Traits>)
Miscellaneous
flushβ synchronizes with the underlying storage device (public member function ofstd::basic_ostream<CharT,Traits>)
Member classes
sentryβ implements basic logic for preparation of the stream for output operations (public member class ofstd::basic_ostream<CharT,Traits>)
πΈ Inherited from std::basic_ios πΈ
Member types
char_typeβCharTtraits_typeβTraitsint_typeβTraits::int_typepos_typeβTraits::pos_typeoff_typeβTraits::off_type
Member functions
State functions
goodβ checks if no error has occurred i.e. I/O operations are available (public member function ofstd::basic_ios<CharT,Traits>)eofβ checks if end-of-file has been reached (public member function ofstd::basic_ios<CharT,Traits>)failβ checks if an error has occurred (public member function ofstd::basic_ios<CharT,Traits>)badβ checks if a non-recoverable error has occurred (public member function ofstd::basic_ios<CharT,Traits>)operator!β checks if an error has occurred (synonym offail()) (public member function ofstd::basic_ios<CharT,Traits>)operator boolβ checks if no error has occurred (synonym of!fail()) (public member function ofstd::basic_ios<CharT,Traits>)rdstateβ returns state flags (public member function ofstd::basic_ios<CharT,Traits>)setstateβ sets state flags (public member function ofstd::basic_ios<CharT,Traits>)clearβ modifies state flags (public member function ofstd::basic_ios<CharT,Traits>)
Formatting
copyfmtβ copies formatting information (public member function ofstd::basic_ios<CharT,Traits>)fillβ manages the fill character (public member function ofstd::basic_ios<CharT,Traits>)
Miscellaneous
exceptionsβ manages exception mask (public member function ofstd::basic_ios<CharT,Traits>)imbueβ sets the locale (public member function ofstd::basic_ios<CharT,Traits>)rdbufβ manages associated stream buffer (public member function ofstd::basic_ios<CharT,Traits>)tieβ manages tied stream (public member function ofstd::basic_ios<CharT,Traits>)narrowβ narrows characters (public member function ofstd::basic_ios<CharT,Traits>)widenβ widens characters (public member function ofstd::basic_ios<CharT,Traits>)
π Inherited from std::ios_base π
Member functions
Formatting
flagsβ manages format flags (public member function ofstd::ios_base)setfβ sets specific format flag (public member function ofstd::ios_base)unsetfβ clears specific format flag (public member function ofstd::ios_base)precisionβ manages decimal precision of floating point operations (public member function ofstd::ios_base)widthβ manages field width (public member function ofstd::ios_base)
Locales
imbueβ sets locale (public member function ofstd::ios_base)getlocβ returns current locale (public member function ofstd::ios_base)
Internal extensible array
xalloc[static]β returns a program-wide unique integer that is safe to use as index topword()andiword()(public static member function ofstd::ios_base)iwordβ resizes the private storage if necessary and access to thelongelement at the given index (public member function ofstd::ios_base)pwordβ resizes the private storage if necessary and access to thevoid*element at the given index (public member function ofstd::ios_base)
Miscellaneous
register_callbackβ registers event callback function (public member function ofstd::ios_base)sync_with_stdio[static]β sets whether C++ and C I/O libraries are interoperable (public static member function ofstd::ios_base)
Member classes
failureβ stream exception (public member class ofstd::ios_base)Initβ initializes standard stream objects (public member class ofstd::ios_base)
Okay so real talk, this whole chunk is basically the β¨constant loreβ¨ β every typedef and every flag value you can throw at the stream, and yes you're gonna wanna know them all, so let's go π
openmodeβ(typedef)the stream open mode type. The following constants are also defined:appβ seek to the end of stream before each writebinaryβ open in binary modeinβ open for readingoutβ open for writingtruncβ discard the contents of the stream when openingateβ seek to the end of stream immediately after opennoreplace(C++23) β open in exclusive mode
fmtflagsβ(typedef)the formatting flags type. The following constants are also defined:decβ use decimal base for integer I/O: seestd::decoctβ use octal base for integer I/O: seestd::octhexβ use hexadecimal base for integer I/O: seestd::hexbasefieldβdec | oct | hex. Useful for masking operationsleftβ left adjustment (adds fill characters to the right): seestd::leftrightβ right adjustment (adds fill characters to the left): seestd::rightinternalβ internal adjustment (adds fill characters to the internal designated point): seestd::internaladjustfieldβleft | right | internal. Useful for masking operationsscientificβ generate floating point types using scientific notation, or hex notation if combined withfixed: seestd::scientificfixedβ generate floating point types using fixed notation, or hex notation if combined withscientific: seestd::fixedfloatfieldβscientific | fixed. Useful for masking operationsboolalphaβ insert and extractbooltype in alphanumeric format: seestd::boolalphashowbaseβ generate a prefix indicating the numeric base for integer output, require the currency indicator in monetary I/O: seestd::showbaseshowpointβ generate a decimal-point character unconditionally for floating-point number output: seestd::showpointshowposβ generate a+character for non-negative numeric output: seestd::showposskipwsβ skip leading whitespace before certain input operations: seestd::skipwsunitbufβ flush the output after each output operation: seestd::unitbufuppercaseβ replace certain lowercase letters with their uppercase equivalents in certain output operations: seestd::uppercase
iostateβ(typedef)the state of the stream type. The following constants are also defined:goodbitβ no errorbadbitβ irrecoverable stream errorfailbitβ input/output operation failed (formatting or extraction error)eofbitβ associated input sequence has reached end-of-file
seekdirβ(typedef)the seeking direction type. The following constants are also defined:begβ the beginning of a streamendβ the ending of a streamcurβ the current position of stream position indicator
eventβ(enum)specifies event typeevent_callbackβ(typedef)callback function type
π‘ Notes π‘
Bestie, there's literally a feature-test macro for this, so you can vibe-check at compile time whether your lib has it π§
__cpp_lib_syncbufβ value201803L, std(C++20), feature: Synchronized buffered ostream (std::osyncstream,std::syncbuf) and manipulators
That's the whole page, no cap π«Ά source is http://cppreference.com, version/date 2024.06.10, and it's std::basic_osyncstream(3) β go yeet it into your build and slay β¨ππ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms