basic_osyncstream( streambuf_type* buf, const Allocator& a );
(1)explicit basic_osyncstream( streambuf_type* buf );
(2) (3) (4) (5)Constructs new synchronized output stream.
5)Move constructor. Move-constructs the
std::basic_ostreambase and the std::basic_syncbuf member from the corresponding subobjects of
other, then calls
set_rdbufwith the pointer to the newly-constructed underlying
std::basic_syncbufto complete the initialization of the base. After this move constructor,
other.get_wrapped()returns
nullptrand destruction of
otherproduces no output.
[edit] Parameters buf - pointer to the std::basic_streambuf that will be wrapped os - reference to a std::basic_ostream, whose rdbuf() will be wrapped a - the allocator to pass to the constructor of the member std::basic_syncbuf other - another osyncstream to move from [edit] Example#include <iostream> #include <string_view> #include <syncstream> #include <thread> void worker(const int id, std::ostream &os) { std::string_view block; switch (id) { default: [[fallthrough]]; case 0: block = "ââ"; break; case 1: block = "ââ"; break; case 2: block = "ââ"; break; case 3: block = "ââ"; break; } for (int i = 1; i <= 50; ++i) os << block << std::flush; os << std::endl; } int main() { std::cout << "Synchronized output should not cause any interference:" << std::endl; { auto scout1 = std::osyncstream{std::cout}; auto scout2 = std::osyncstream{std::cout}; auto scout3 = std::osyncstream{std::cout}; auto scout4 = std::osyncstream{std::cout}; auto w1 = std::jthread{worker, 0, std::ref(scout1)}; auto w2 = std::jthread{worker, 1, std::ref(scout2)}; auto w3 = std::jthread{worker, 2, std::ref(scout3)}; auto w4 = std::jthread{worker, 3, std::ref(scout4)}; } std::cout << "\nLack of synchronization may cause some interference on output:" << std::endl; { auto w1 = std::jthread{worker, 0, std::ref(std::cout)}; auto w2 = std::jthread{worker, 1, std::ref(std::cout)}; auto w3 = std::jthread{worker, 2, std::ref(std::cout)}; auto w4 = std::jthread{worker, 3, std::ref(std::cout)}; } }
Possible output:
Synchronized output should not cause any interference: ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ Lack of synchronization may cause some interference on output: ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ ââââââ[edit] See also constructs a
basic_syncbuf
object
std::basic_syncbuf<CharT,Traits,Allocator>
) [edit]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4