std::basic_osyncstream(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸŽ€ 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 β€” CharT
  • traits_type β€” Traits; the program is ill-formed if Traits::char_type is not CharT. periodt, the compiler will absolutely clock that πŸ’€
  • int_type β€” Traits::int_type
  • pos_type β€” Traits::pos_type
  • off_type β€” Traits::off_type
  • allocator_type β€” Allocator
  • streambuf_type β€” std::basic_streambuf<CharT, Traits>
  • syncbuf_type β€” std::basic_syncbuf<CharT, Traits, Allocator>

πŸ› οΈ Member functions πŸ› οΈ

  • constructor β€” constructs a basic_osyncstream object (public member function)
  • operator= β€” assigns a basic_osyncstream object (public member function)
  • destructor β€” destroys the basic_osyncstream and emits its internal buffer (public member function)
  • rdbuf β€” obtains a pointer to the underlying basic_syncbuf (public member function)
  • get_wrapped β€” obtains a pointer to the final destination stream buffer (public member function)
  • emit β€” calls emit() on the underlying basic_syncbuf to 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 of std::basic_ostream<CharT,Traits>)

Unformatted output

  • put β€” inserts a character (public member function of std::basic_ostream<CharT,Traits>)
  • write β€” inserts blocks of characters (public member function of std::basic_ostream<CharT,Traits>)

Positioning

  • tellp β€” returns the output position indicator (public member function of std::basic_ostream<CharT,Traits>)
  • seekp β€” sets the output position indicator (public member function of std::basic_ostream<CharT,Traits>)

Miscellaneous

  • flush β€” synchronizes with the underlying storage device (public member function of std::basic_ostream<CharT,Traits>)

Member classes

  • sentry β€” implements basic logic for preparation of the stream for output operations (public member class of std::basic_ostream<CharT,Traits>)

🌸 Inherited from std::basic_ios 🌸

Member types

  • char_type β€” CharT
  • traits_type β€” Traits
  • int_type β€” Traits::int_type
  • pos_type β€” Traits::pos_type
  • off_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 of std::basic_ios<CharT,Traits>)
  • eof β€” checks if end-of-file has been reached (public member function of std::basic_ios<CharT,Traits>)
  • fail β€” checks if an error has occurred (public member function of std::basic_ios<CharT,Traits>)
  • bad β€” checks if a non-recoverable error has occurred (public member function of std::basic_ios<CharT,Traits>)
  • operator! β€” checks if an error has occurred (synonym of fail()) (public member function of std::basic_ios<CharT,Traits>)
  • operator bool β€” checks if no error has occurred (synonym of !fail()) (public member function of std::basic_ios<CharT,Traits>)
  • rdstate β€” returns state flags (public member function of std::basic_ios<CharT,Traits>)
  • setstate β€” sets state flags (public member function of std::basic_ios<CharT,Traits>)
  • clear β€” modifies state flags (public member function of std::basic_ios<CharT,Traits>)

Formatting

  • copyfmt β€” copies formatting information (public member function of std::basic_ios<CharT,Traits>)
  • fill β€” manages the fill character (public member function of std::basic_ios<CharT,Traits>)

Miscellaneous

  • exceptions β€” manages exception mask (public member function of std::basic_ios<CharT,Traits>)
  • imbue β€” sets the locale (public member function of std::basic_ios<CharT,Traits>)
  • rdbuf β€” manages associated stream buffer (public member function of std::basic_ios<CharT,Traits>)
  • tie β€” manages tied stream (public member function of std::basic_ios<CharT,Traits>)
  • narrow β€” narrows characters (public member function of std::basic_ios<CharT,Traits>)
  • widen β€” widens characters (public member function of std::basic_ios<CharT,Traits>)

πŸ‘‘ Inherited from std::ios_base πŸ‘‘

Member functions

Formatting

  • flags β€” manages format flags (public member function of std::ios_base)
  • setf β€” sets specific format flag (public member function of std::ios_base)
  • unsetf β€” clears specific format flag (public member function of std::ios_base)
  • precision β€” manages decimal precision of floating point operations (public member function of std::ios_base)
  • width β€” manages field width (public member function of std::ios_base)

Locales

  • imbue β€” sets locale (public member function of std::ios_base)
  • getloc β€” returns current locale (public member function of std::ios_base)

Internal extensible array

  • xalloc [static] β€” returns a program-wide unique integer that is safe to use as index to pword() and iword() (public static member function of std::ios_base)
  • iword β€” resizes the private storage if necessary and access to the long element at the given index (public member function of std::ios_base)
  • pword β€” resizes the private storage if necessary and access to the void* element at the given index (public member function of std::ios_base)

Miscellaneous

  • register_callback β€” registers event callback function (public member function of std::ios_base)
  • sync_with_stdio [static] β€” sets whether C++ and C I/O libraries are interoperable (public static member function of std::ios_base)

Member classes

  • failure β€” stream exception (public member class of std::ios_base)
  • Init β€” initializes standard stream objects (public member class of std::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 write
    • binary β€” open in binary mode
    • in β€” open for reading
    • out β€” open for writing
    • trunc β€” discard the contents of the stream when opening
    • ate β€” seek to the end of stream immediately after open
    • noreplace (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: see std::dec
    • oct β€” use octal base for integer I/O: see std::oct
    • hex β€” use hexadecimal base for integer I/O: see std::hex
    • basefield β€” dec | oct | hex. Useful for masking operations
    • left β€” left adjustment (adds fill characters to the right): see std::left
    • right β€” right adjustment (adds fill characters to the left): see std::right
    • internal β€” internal adjustment (adds fill characters to the internal designated point): see std::internal
    • adjustfield β€” left | right | internal. Useful for masking operations
    • scientific β€” generate floating point types using scientific notation, or hex notation if combined with fixed: see std::scientific
    • fixed β€” generate floating point types using fixed notation, or hex notation if combined with scientific: see std::fixed
    • floatfield β€” scientific | fixed. Useful for masking operations
    • boolalpha β€” insert and extract bool type in alphanumeric format: see std::boolalpha
    • showbase β€” generate a prefix indicating the numeric base for integer output, require the currency indicator in monetary I/O: see std::showbase
    • showpoint β€” generate a decimal-point character unconditionally for floating-point number output: see std::showpoint
    • showpos β€” generate a + character for non-negative numeric output: see std::showpos
    • skipws β€” skip leading whitespace before certain input operations: see std::skipws
    • unitbuf β€” flush the output after each output operation: see std::unitbuf
    • uppercase β€” replace certain lowercase letters with their uppercase equivalents in certain output operations: see std::uppercase
  • iostate β€” (typedef) the state of the stream type. The following constants are also defined:
    • goodbit β€” no error
    • badbit β€” irrecoverable stream error
    • failbit β€” 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 stream
    • end β€” the ending of a stream
    • cur β€” the current position of stream position indicator
  • event β€” (enum) specifies event type
  • event_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 β€” value 201803L, 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