std::basic_osyncstream (3) - Linux Manuals
std::basic_osyncstream: std::basic_osyncstream
NAME
std::basic_osyncstream - std::basic_osyncstream
Synopsis
Defined in header <syncstream>
template<
class CharT,
class Traits = std::char_traits<CharT>, (since C++20)
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.
It can be used with a named variable:
as well as with a temporary:
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 the that final destination buffer is made through (possibly different) instances of std::basic_osyncstream.
Typical implementation of std::basic_osyncstream holds only one member: the wrapped std::basic_syncbuf
Two specializations for common character types are also defined:
Defined in header <syncstream>
Type Definition
osyncstream basic_osyncstream<char>
wosyncstream basic_osyncstream<wchar_t>
Member types
Member type Definition
char_type CharT
traits_type Traits; the program is ill-formed if Traits::char_type is not CharT.
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 (public member function)
operator= (public member function)
destructor (public member function)
rdbuf (public member function)
get_wrapped (public member function)
emit (public member function)
Inherited from std::basic_ostream
Member functions
Formatted output
operator<< (public member function of std::basic_ostream<CharT,Traits>)
Unformatted output
put (public member function of std::basic_ostream<CharT,Traits>)
write (public member function of std::basic_ostream<CharT,Traits>)
Positioning
tellp (public member function of std::basic_ostream<CharT,Traits>)
seekp (public member function of std::basic_ostream<CharT,Traits>)
Miscellaneous
flush (public member function of std::basic_ostream<CharT,Traits>)
Member classes
sentry (public member class of std::basic_ostream<CharT,Traits>)
Inherited from std::basic_ios
Member types
Member type Definition
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 (public member function of std::basic_ios<CharT,Traits>)
eof (public member function of std::basic_ios<CharT,Traits>)
fail (public member function of std::basic_ios<CharT,Traits>)
bad (public member function of std::basic_ios<CharT,Traits>)
operator! (public member function of std::basic_ios<CharT,Traits>)
operator_void*
operator_bool checks if no error has occurred (synonym of !fail())