This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

View File

@@ -0,0 +1,174 @@
[syncstream.osyncstream]
# 31 Input/output library [[input.output]](./#input.output)
## 31.11 Synchronized output streams [[syncstream]](syncstream#osyncstream)
### 31.11.3 Class template basic_osyncstream [syncstream.osyncstream]
#### [31.11.3.1](#overview) Overview [[syncstream.osyncstream.overview]](syncstream.osyncstream.overview)
[🔗](#lib:basic_osyncstream)
namespace std {template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>class basic_osyncstream : public basic_ostream<charT, traits> {public:using char_type = charT; using int_type = typename traits::int_type; using pos_type = typename traits::pos_type; using off_type = typename traits::off_type; using traits_type = traits; using allocator_type = Allocator; using streambuf_type = basic_streambuf<charT, traits>; using syncbuf_type = basic_syncbuf<charT, traits, Allocator>; // [[syncstream.osyncstream.cons]](#cons "31.11.3.2Construction and destruction"), construction and destruction basic_osyncstream(streambuf_type*, const Allocator&); explicit basic_osyncstream(streambuf_type* obuf): basic_osyncstream(obuf, Allocator()) {} basic_osyncstream(basic_ostream<charT, traits>& os, const Allocator& allocator): basic_osyncstream(os.rdbuf(), allocator) {}explicit basic_osyncstream(basic_ostream<charT, traits>& os): basic_osyncstream(os, Allocator()) {} basic_osyncstream(basic_osyncstream&&) noexcept; ~basic_osyncstream(); // assignment basic_osyncstream& operator=(basic_osyncstream&&); // [[syncstream.osyncstream.members]](#members "31.11.3.3Member functions"), member functionsvoid emit();
streambuf_type* get_wrapped() const noexcept;
syncbuf_type* rdbuf() const noexcept { return const_cast<syncbuf_type*>(addressof(*sb*)); }private: syncbuf_type *sb*; // *exposition only*};}
[1](#overview-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12958)
Allocator shall meet
the [*Cpp17Allocator*](allocator.requirements.general#:Cpp17Allocator "16.4.4.6.1General[allocator.requirements.general]") requirements ([[allocator.requirements.general]](allocator.requirements.general "16.4.4.6.1General"))[.](#overview-1.sentence-1)
[2](#overview-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12962)
[*Example [1](#overview-example-1)*:
A named variable can be used within a block statement for streaming[.](#overview-2.sentence-1)
{ osyncstream bout(cout);
bout << "Hello, ";
bout << "World!";
bout << endl; // flush is noted bout << "and more!\n";} // characters are transferred and cout is flushed — *end example*]
[3](#overview-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12976)
[*Example [2](#overview-example-2)*:
A temporary object can be used for streaming within a single statement[.](#overview-3.sentence-1)
osyncstream(cout) << "Hello, " << "World!" << '\n';
In this example, cout is not flushed[.](#overview-3.sentence-2)
— *end example*]
#### [31.11.3.2](#cons) Construction and destruction [[syncstream.osyncstream.cons]](syncstream.osyncstream.cons)
[🔗](#lib:basic_osyncstream,constructor)
`basic_osyncstream(streambuf_type* buf, const Allocator& allocator);
`
[1](#cons-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12993)
*Effects*: Initializes *sb* from buf and allocator[.](#cons-1.sentence-1)
Initializes the base class with basic_ostream<charT, traits>(addressof(*sb*))[.](#cons-1.sentence-2)
[2](#cons-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12998)
[*Note [1](#cons-note-1)*:
The member functions of the provided stream buffer
can be called from emit() while a lock is held,
which might result in a deadlock if used incautiously[.](#cons-2.sentence-1)
— *end note*]
[3](#cons-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13005)
*Postconditions*: get_wrapped() == buf is true[.](#cons-3.sentence-1)
[🔗](#lib:basic_osyncstream,constructor_)
`basic_osyncstream(basic_osyncstream&& other) noexcept;
`
[4](#cons-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13016)
*Effects*: Move constructs the base class
and *sb* from the corresponding subobjects of other,
and calls basic_ostream<charT, traits>::set_rdbuf(addressof(*sb*))[.](#cons-4.sentence-1)
[5](#cons-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13022)
*Postconditions*: The value returned by get_wrapped() is the value returned by other.get_wrapped() prior to calling this constructor[.](#cons-5.sentence-1)
nullptr == other.get_wrapped() is true[.](#cons-5.sentence-2)
#### [31.11.3.3](#members) Member functions [[syncstream.osyncstream.members]](syncstream.osyncstream.members)
[🔗](#lib:set_emit_on_sync,basic_osyncstream)
`void emit();
`
[1](#members-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13038)
*Effects*: Behaves as an unformatted output function ([[ostream.unformatted]](ostream.unformatted "31.7.6.4Unformatted output functions"))[.](#members-1.sentence-1)
After constructing a sentry object, calls *sb*.emit()[.](#members-1.sentence-2)
If that call returns false,
calls setstate(ios_base::badbit)[.](#members-1.sentence-3)
[2](#members-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13045)
[*Example [1](#members-example-1)*:
A flush on a basic_osyncstream does not flush immediately:{ osyncstream bout(cout);
bout << "Hello," << '\n'; // no flush bout.emit(); // characters transferred; cout not flushed bout << "World!" << endl; // flush noted; cout not flushed bout.emit(); // characters transferred; cout flushed bout << "Greetings." << '\n'; // no flush} // characters transferred; cout not flushed
— *end example*]
[3](#members-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13060)
[*Example [2](#members-example-2)*:
The function emit() can be used to
handle exceptions from operations on the underlying stream[.](#members-3.sentence-1)
{ osyncstream bout(cout);
bout << "Hello, " << "World!" << '\n'; try { bout.emit(); } catch (...) {// handle exception}} — *end example*]
[🔗](#lib:set_emit_on_sync,basic_osyncstream_)
`streambuf_type* get_wrapped() const noexcept;
`
[4](#members-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13084)
*Returns*: *sb*.get_wrapped()[.](#members-4.sentence-1)
[5](#members-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13088)
[*Example [3](#members-example-3)*:
Obtaining the wrapped stream buffer with get_wrapped() allows wrapping it again with an osyncstream[.](#members-5.sentence-1)
For example,{ osyncstream bout1(cout);
bout1 << "Hello, "; { osyncstream(bout1.get_wrapped()) << "Goodbye, " << "Planet!" << '\n'; } bout1 << "World!" << '\n';} produces the *uninterleaved* output
```
Goodbye, Planet!
Hello, World!
```
— *end example*]

View File

@@ -0,0 +1,61 @@
[syncstream.osyncstream.cons]
# 31 Input/output library [[input.output]](./#input.output)
## 31.11 Synchronized output streams [[syncstream]](syncstream#osyncstream.cons)
### 31.11.3 Class template basic_osyncstream [[syncstream.osyncstream]](syncstream.osyncstream#cons)
#### 31.11.3.2 Construction and destruction [syncstream.osyncstream.cons]
[🔗](#lib:basic_osyncstream,constructor)
`basic_osyncstream(streambuf_type* buf, const Allocator& allocator);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12993)
*Effects*: Initializes *sb* from buf and allocator[.](#1.sentence-1)
Initializes the base class with basic_ostream<charT, traits>(addressof(*sb*))[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12998)
[*Note [1](#note-1)*:
The member functions of the provided stream buffer
can be called from emit() while a lock is held,
which might result in a deadlock if used incautiously[.](#2.sentence-1)
— *end note*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13005)
*Postconditions*: get_wrapped() == buf is true[.](#3.sentence-1)
[🔗](#lib:basic_osyncstream,constructor_)
`basic_osyncstream(basic_osyncstream&& other) noexcept;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13016)
*Effects*: Move constructs the base class
and *sb* from the corresponding subobjects of other,
and calls basic_ostream<charT, traits>::set_rdbuf(addressof(*sb*))[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13022)
*Postconditions*: The value returned by get_wrapped() is the value returned by other.get_wrapped() prior to calling this constructor[.](#5.sentence-1)
nullptr == other.get_wrapped() is true[.](#5.sentence-2)

View File

@@ -0,0 +1,78 @@
[syncstream.osyncstream.members]
# 31 Input/output library [[input.output]](./#input.output)
## 31.11 Synchronized output streams [[syncstream]](syncstream#osyncstream.members)
### 31.11.3 Class template basic_osyncstream [[syncstream.osyncstream]](syncstream.osyncstream#members)
#### 31.11.3.3 Member functions [syncstream.osyncstream.members]
[🔗](#lib:set_emit_on_sync,basic_osyncstream)
`void emit();
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13038)
*Effects*: Behaves as an unformatted output function ([[ostream.unformatted]](ostream.unformatted "31.7.6.4Unformatted output functions"))[.](#1.sentence-1)
After constructing a sentry object, calls *sb*.emit()[.](#1.sentence-2)
If that call returns false,
calls setstate(ios_base::badbit)[.](#1.sentence-3)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13045)
[*Example [1](#example-1)*:
A flush on a basic_osyncstream does not flush immediately:{ osyncstream bout(cout);
bout << "Hello," << '\n'; // no flush bout.emit(); // characters transferred; cout not flushed bout << "World!" << endl; // flush noted; cout not flushed bout.emit(); // characters transferred; cout flushed bout << "Greetings." << '\n'; // no flush} // characters transferred; cout not flushed
— *end example*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13060)
[*Example [2](#example-2)*:
The function emit() can be used to
handle exceptions from operations on the underlying stream[.](#3.sentence-1)
{ osyncstream bout(cout);
bout << "Hello, " << "World!" << '\n'; try { bout.emit(); } catch (...) {// handle exception}} — *end example*]
[🔗](#lib:set_emit_on_sync,basic_osyncstream_)
`streambuf_type* get_wrapped() const noexcept;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13084)
*Returns*: *sb*.get_wrapped()[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13088)
[*Example [3](#example-3)*:
Obtaining the wrapped stream buffer with get_wrapped() allows wrapping it again with an osyncstream[.](#5.sentence-1)
For example,{ osyncstream bout1(cout);
bout1 << "Hello, "; { osyncstream(bout1.get_wrapped()) << "Goodbye, " << "Planet!" << '\n'; } bout1 << "World!" << '\n';} produces the *uninterleaved* output
```
Goodbye, Planet!
Hello, World!
```
— *end example*]

View File

@@ -0,0 +1,49 @@
[syncstream.osyncstream.overview]
# 31 Input/output library [[input.output]](./#input.output)
## 31.11 Synchronized output streams [[syncstream]](syncstream#osyncstream.overview)
### 31.11.3 Class template basic_osyncstream [[syncstream.osyncstream]](syncstream.osyncstream#overview)
#### 31.11.3.1 Overview [syncstream.osyncstream.overview]
[🔗](#lib:basic_osyncstream)
namespace std {template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>class basic_osyncstream : public basic_ostream<charT, traits> {public:using char_type = charT; using int_type = typename traits::int_type; using pos_type = typename traits::pos_type; using off_type = typename traits::off_type; using traits_type = traits; using allocator_type = Allocator; using streambuf_type = basic_streambuf<charT, traits>; using syncbuf_type = basic_syncbuf<charT, traits, Allocator>; // [[syncstream.osyncstream.cons]](syncstream.osyncstream.cons "31.11.3.2Construction and destruction"), construction and destruction basic_osyncstream(streambuf_type*, const Allocator&); explicit basic_osyncstream(streambuf_type* obuf): basic_osyncstream(obuf, Allocator()) {} basic_osyncstream(basic_ostream<charT, traits>& os, const Allocator& allocator): basic_osyncstream(os.rdbuf(), allocator) {}explicit basic_osyncstream(basic_ostream<charT, traits>& os): basic_osyncstream(os, Allocator()) {} basic_osyncstream(basic_osyncstream&&) noexcept; ~basic_osyncstream(); // assignment basic_osyncstream& operator=(basic_osyncstream&&); // [[syncstream.osyncstream.members]](syncstream.osyncstream.members "31.11.3.3Member functions"), member functionsvoid emit();
streambuf_type* get_wrapped() const noexcept;
syncbuf_type* rdbuf() const noexcept { return const_cast<syncbuf_type*>(addressof(*sb*)); }private: syncbuf_type *sb*; // *exposition only*};}
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12958)
Allocator shall meet
the [*Cpp17Allocator*](allocator.requirements.general#:Cpp17Allocator "16.4.4.6.1General[allocator.requirements.general]") requirements ([[allocator.requirements.general]](allocator.requirements.general "16.4.4.6.1General"))[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12962)
[*Example [1](#example-1)*:
A named variable can be used within a block statement for streaming[.](#2.sentence-1)
{ osyncstream bout(cout);
bout << "Hello, ";
bout << "World!";
bout << endl; // flush is noted bout << "and more!\n";} // characters are transferred and cout is flushed — *end example*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12976)
[*Example [2](#example-2)*:
A temporary object can be used for streaming within a single statement[.](#3.sentence-1)
osyncstream(cout) << "Hello, " << "World!" << '\n';
In this example, cout is not flushed[.](#3.sentence-2)
— *end example*]

View File

@@ -0,0 +1,19 @@
[syncstream.syn]
# 31 Input/output library [[input.output]](./#input.output)
## 31.11 Synchronized output streams [[syncstream]](syncstream#syn)
### 31.11.1 Header <syncstream> synopsis [syncstream.syn]
[🔗](#header:%3csyncstream%3e)
#include <ostream> // see [[ostream.syn]](ostream.syn "31.7.2Header <ostream> synopsis")namespace std {// [[syncstream.syncbuf]](syncstream.syncbuf "31.11.2Class template basic_­syncbuf"), class template basic_syncbuftemplate<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>class basic_syncbuf; // [[syncstream.syncbuf.special]](syncstream.syncbuf.special "31.11.2.6Specialized algorithms"), specialized algorithmstemplate<class charT, class traits, class Allocator>void swap(basic_syncbuf<charT, traits, Allocator>&,
basic_syncbuf<charT, traits, Allocator>&); using syncbuf = basic_syncbuf<char>; using wsyncbuf = basic_syncbuf<wchar_t>; // [[syncstream.osyncstream]](syncstream.osyncstream "31.11.3Class template basic_­osyncstream"), class template basic_osyncstreamtemplate<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>class basic_osyncstream; using osyncstream = basic_osyncstream<char>; using wosyncstream = basic_osyncstream<wchar_t>;}
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12596)
The header [<syncstream>](#header:%3csyncstream%3e "31.11.1Header <syncstream> synopsis[syncstream.syn]") provides a mechanism
to synchronize execution agents writing to the same stream[.](#1.sentence-1)

View File

@@ -0,0 +1,309 @@
[syncstream.syncbuf]
# 31 Input/output library [[input.output]](./#input.output)
## 31.11 Synchronized output streams [[syncstream]](syncstream#syncbuf)
### 31.11.2 Class template basic_syncbuf [syncstream.syncbuf]
#### [31.11.2.1](#overview) Overview [[syncstream.syncbuf.overview]](syncstream.syncbuf.overview)
[🔗](#lib:basic_syncbuf)
namespace std {template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>class basic_syncbuf : public basic_streambuf<charT, traits> {public:using char_type = charT; using int_type = typename traits::int_type; using pos_type = typename traits::pos_type; using off_type = typename traits::off_type; using traits_type = traits; using allocator_type = Allocator; using streambuf_type = basic_streambuf<charT, traits>; // [[syncstream.syncbuf.cons]](#cons "31.11.2.2Construction and destruction"), construction and destruction basic_syncbuf(): basic_syncbuf(nullptr) {}explicit basic_syncbuf(streambuf_type* obuf): basic_syncbuf(obuf, Allocator()) {} basic_syncbuf(streambuf_type*, const Allocator&);
basic_syncbuf(basic_syncbuf&&); ~basic_syncbuf(); // [[syncstream.syncbuf.assign]](#assign "31.11.2.3Assignment and swap"), assignment and swap basic_syncbuf& operator=(basic_syncbuf&&); void swap(basic_syncbuf&); // [[syncstream.syncbuf.members]](#members "31.11.2.4Member functions"), member functionsbool emit();
streambuf_type* get_wrapped() const noexcept;
allocator_type get_allocator() const noexcept; void set_emit_on_sync(bool) noexcept; protected:// [[syncstream.syncbuf.virtuals]](#virtuals "31.11.2.5Overridden virtual functions"), overridden virtual functionsint sync() override; private: streambuf_type* *wrapped*; // *exposition only*bool *emit-on-sync*{}; // *exposition only*};}
[1](#overview-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12649)
Class template basic_syncbuf stores character data
written to it, known as the associated output, into internal
buffers allocated using the object's allocator[.](#overview-1.sentence-1)
The associated output is transferred to the
wrapped stream buffer object **wrapped* when emit() is called
or when the basic_syncbuf object is destroyed[.](#overview-1.sentence-2)
Such transfers are atomic with respect to transfers
by other basic_syncbuf objects
with the same wrapped stream buffer object[.](#overview-1.sentence-3)
#### [31.11.2.2](#cons) Construction and destruction [[syncstream.syncbuf.cons]](syncstream.syncbuf.cons)
[🔗](#lib:basic_syncbuf,constructor)
`basic_syncbuf(streambuf_type* obuf, const Allocator& allocator);
`
[1](#cons-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12669)
*Effects*: Sets *wrapped* to obuf[.](#cons-1.sentence-1)
[2](#cons-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12673)
*Postconditions*: get_wrapped() == obuf andget_allocator() == allocator are true[.](#cons-2.sentence-1)
[3](#cons-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12678)
*Throws*: Nothing unless an exception is thrown
by the construction of a mutex or
by memory allocation[.](#cons-3.sentence-1)
[4](#cons-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12684)
*Remarks*: A copy of allocator is used
to allocate memory for internal buffers
holding the associated output[.](#cons-4.sentence-1)
[🔗](#lib:basic_syncbuf,constructor_)
`basic_syncbuf(basic_syncbuf&& other);
`
[5](#cons-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12697)
*Postconditions*: The value returned by this->get_wrapped() is the value returned by other.get_wrapped() prior to calling this constructor[.](#cons-5.sentence-1)
Output stored in other prior to calling this constructor
will be stored in *this afterwards[.](#cons-5.sentence-2)
other.pbase() == other.pptr() andother.get_wrapped() == nullptr are true[.](#cons-5.sentence-3)
[6](#cons-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12710)
*Remarks*: This constructor disassociates other from its wrapped stream buffer,
ensuring destruction of other produces no output[.](#cons-6.sentence-1)
[🔗](#lib:basic_syncbuf,destructor)
`~basic_syncbuf();
`
[7](#cons-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12723)
*Effects*: Calls emit()[.](#cons-7.sentence-1)
[8](#cons-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12727)
*Throws*: Nothing[.](#cons-8.sentence-1)
If an exception is thrown from emit(),
the destructor catches and ignores that exception[.](#cons-8.sentence-2)
#### [31.11.2.3](#assign) Assignment and swap [[syncstream.syncbuf.assign]](syncstream.syncbuf.assign)
[🔗](#lib:operator=,basic_syncbuf)
`basic_syncbuf& operator=(basic_syncbuf&& rhs);
`
[1](#assign-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12742)
*Effects*: Calls emit() then
move assigns from rhs[.](#assign-1.sentence-1)
After the move assignment *this has the observable state it would have had if
it had been move constructed from rhs ([[syncstream.syncbuf.cons]](#cons "31.11.2.2Construction and destruction"))[.](#assign-1.sentence-2)
[2](#assign-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12750)
*Postconditions*:
- [(2.1)](#assign-2.1)
rhs.get_wrapped() == nullptr is true.
- [(2.2)](#assign-2.2)
this->get_allocator() == rhs.get_allocator() is true whenallocator_traits<Allocator>::propagate_on_container_move_assignment::value is true; otherwise, the allocator is unchanged.
[3](#assign-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12763)
*Returns*: *this[.](#assign-3.sentence-1)
[4](#assign-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12767)
*Remarks*: This assignment operator disassociates rhs from its wrapped stream buffer,
ensuring destruction of rhs produces no output[.](#assign-4.sentence-1)
[🔗](#lib:swap,basic_syncbuf)
`void swap(basic_syncbuf& other);
`
[5](#assign-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12780)
*Preconditions*: Eitherallocator_traits<Allocator>::propagate_on_container_swap::value is true orthis->get_allocator() == other.get_allocator() is true[.](#assign-5.sentence-1)
[6](#assign-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12789)
*Effects*: Exchanges the state of *this and other[.](#assign-6.sentence-1)
#### [31.11.2.4](#members) Member functions [[syncstream.syncbuf.members]](syncstream.syncbuf.members)
[🔗](#lib:emit,basic_syncbuf)
`bool emit();
`
[1](#members-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12802)
*Effects*: Atomically transfers the associated output of *this to the stream buffer **wrapped*,
so that it appears in the output stream
as a contiguous sequence of characters[.](#members-1.sentence-1)
*wrapped*->pubsync() is called
if and only if a call was made to sync() since the most recent call to emit(), if any[.](#members-1.sentence-2)
[2](#members-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12812)
*Synchronization*: All emit() calls transferring characters
to the same stream buffer object
appear to execute in a total order
consistent with the “happens before” relation ([[intro.races]](intro.races "6.10.2.2Data races")),
where each emit() call
synchronizes with
subsequent emit() calls in that total order[.](#members-2.sentence-1)
[3](#members-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12822)
*Postconditions*: On success, the associated output is empty[.](#members-3.sentence-1)
[4](#members-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12826)
*Returns*: true if all of the following conditions hold;
otherwise false:
- [(4.1)](#members-4.1)
*wrapped* == nullptr is false[.](#members-4.1.sentence-1)
- [(4.2)](#members-4.2)
All of the characters in the associated output were successfully transferred[.](#members-4.2.sentence-1)
- [(4.3)](#members-4.3)
The call to *wrapped*->pubsync() (if any) succeeded[.](#members-4.3.sentence-1)
[5](#members-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12836)
*Remarks*: May call member functions of *wrapped* while holding a lock uniquely associated with *wrapped*[.](#members-5.sentence-1)
[🔗](#lib:get_wrapped,basic_syncbuf)
`streambuf_type* get_wrapped() const noexcept;
`
[6](#members-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12848)
*Returns*: *wrapped*[.](#members-6.sentence-1)
[🔗](#lib:get_allocator,basic_syncbuf)
`allocator_type get_allocator() const noexcept;
`
[7](#members-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12859)
*Returns*: A copy of the allocator that was set in the constructor or assignment operator[.](#members-7.sentence-1)
[🔗](#lib:set_emit_on_sync,basic_syncbuf)
`void set_emit_on_sync(bool b) noexcept;
`
[8](#members-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12870)
*Effects*: *emit-on-sync* = b[.](#members-8.sentence-1)
#### [31.11.2.5](#virtuals) Overridden virtual functions [[syncstream.syncbuf.virtuals]](syncstream.syncbuf.virtuals)
[🔗](#lib:sync,basic_syncbuf)
`int sync() override;
`
[1](#virtuals-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12883)
*Effects*: Records that the wrapped stream buffer is to be flushed[.](#virtuals-1.sentence-1)
Then, if *emit-on-sync* is true, calls emit()[.](#virtuals-1.sentence-2)
[*Note [1](#virtuals-note-1)*:
If *emit-on-sync* is false,
the actual flush is delayed until a call to emit()[.](#virtuals-1.sentence-3)
— *end note*]
[2](#virtuals-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12892)
*Returns*: If emit() was called and returned false,
returns -1; otherwise 0[.](#virtuals-2.sentence-1)
#### [31.11.2.6](#special) Specialized algorithms [[syncstream.syncbuf.special]](syncstream.syncbuf.special)
[🔗](#lib:swap,basic_syncbuf_)
`template<class charT, class traits, class Allocator>
void swap(basic_syncbuf<charT, traits, Allocator>& a,
basic_syncbuf<charT, traits, Allocator>& b);
`
[1](#special-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12908)
*Effects*: Equivalent to a.swap(b)[.](#special-1.sentence-1)

View File

@@ -0,0 +1,68 @@
[syncstream.syncbuf.assign]
# 31 Input/output library [[input.output]](./#input.output)
## 31.11 Synchronized output streams [[syncstream]](syncstream#syncbuf.assign)
### 31.11.2 Class template basic_syncbuf [[syncstream.syncbuf]](syncstream.syncbuf#assign)
#### 31.11.2.3 Assignment and swap [syncstream.syncbuf.assign]
[🔗](#lib:operator=,basic_syncbuf)
`basic_syncbuf& operator=(basic_syncbuf&& rhs);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12742)
*Effects*: Calls emit() then
move assigns from rhs[.](#1.sentence-1)
After the move assignment *this has the observable state it would have had if
it had been move constructed from rhs ([[syncstream.syncbuf.cons]](syncstream.syncbuf.cons "31.11.2.2Construction and destruction"))[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12750)
*Postconditions*:
- [(2.1)](#2.1)
rhs.get_wrapped() == nullptr is true.
- [(2.2)](#2.2)
this->get_allocator() == rhs.get_allocator() is true whenallocator_traits<Allocator>::propagate_on_container_move_assignment::value is true; otherwise, the allocator is unchanged.
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12763)
*Returns*: *this[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12767)
*Remarks*: This assignment operator disassociates rhs from its wrapped stream buffer,
ensuring destruction of rhs produces no output[.](#4.sentence-1)
[🔗](#lib:swap,basic_syncbuf)
`void swap(basic_syncbuf& other);
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12780)
*Preconditions*: Eitherallocator_traits<Allocator>::propagate_on_container_swap::value is true orthis->get_allocator() == other.get_allocator() is true[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12789)
*Effects*: Exchanges the state of *this and other[.](#6.sentence-1)

View File

@@ -0,0 +1,85 @@
[syncstream.syncbuf.cons]
# 31 Input/output library [[input.output]](./#input.output)
## 31.11 Synchronized output streams [[syncstream]](syncstream#syncbuf.cons)
### 31.11.2 Class template basic_syncbuf [[syncstream.syncbuf]](syncstream.syncbuf#cons)
#### 31.11.2.2 Construction and destruction [syncstream.syncbuf.cons]
[🔗](#lib:basic_syncbuf,constructor)
`basic_syncbuf(streambuf_type* obuf, const Allocator& allocator);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12669)
*Effects*: Sets *wrapped* to obuf[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12673)
*Postconditions*: get_wrapped() == obuf andget_allocator() == allocator are true[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12678)
*Throws*: Nothing unless an exception is thrown
by the construction of a mutex or
by memory allocation[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12684)
*Remarks*: A copy of allocator is used
to allocate memory for internal buffers
holding the associated output[.](#4.sentence-1)
[🔗](#lib:basic_syncbuf,constructor_)
`basic_syncbuf(basic_syncbuf&& other);
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12697)
*Postconditions*: The value returned by this->get_wrapped() is the value returned by other.get_wrapped() prior to calling this constructor[.](#5.sentence-1)
Output stored in other prior to calling this constructor
will be stored in *this afterwards[.](#5.sentence-2)
other.pbase() == other.pptr() andother.get_wrapped() == nullptr are true[.](#5.sentence-3)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12710)
*Remarks*: This constructor disassociates other from its wrapped stream buffer,
ensuring destruction of other produces no output[.](#6.sentence-1)
[🔗](#lib:basic_syncbuf,destructor)
`~basic_syncbuf();
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12723)
*Effects*: Calls emit()[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12727)
*Throws*: Nothing[.](#8.sentence-1)
If an exception is thrown from emit(),
the destructor catches and ignores that exception[.](#8.sentence-2)

View File

@@ -0,0 +1,101 @@
[syncstream.syncbuf.members]
# 31 Input/output library [[input.output]](./#input.output)
## 31.11 Synchronized output streams [[syncstream]](syncstream#syncbuf.members)
### 31.11.2 Class template basic_syncbuf [[syncstream.syncbuf]](syncstream.syncbuf#members)
#### 31.11.2.4 Member functions [syncstream.syncbuf.members]
[🔗](#lib:emit,basic_syncbuf)
`bool emit();
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12802)
*Effects*: Atomically transfers the associated output of *this to the stream buffer **wrapped*,
so that it appears in the output stream
as a contiguous sequence of characters[.](#1.sentence-1)
*wrapped*->pubsync() is called
if and only if a call was made to sync() since the most recent call to emit(), if any[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12812)
*Synchronization*: All emit() calls transferring characters
to the same stream buffer object
appear to execute in a total order
consistent with the “happens before” relation ([[intro.races]](intro.races "6.10.2.2Data races")),
where each emit() call
synchronizes with
subsequent emit() calls in that total order[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12822)
*Postconditions*: On success, the associated output is empty[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12826)
*Returns*: true if all of the following conditions hold;
otherwise false:
- [(4.1)](#4.1)
*wrapped* == nullptr is false[.](#4.1.sentence-1)
- [(4.2)](#4.2)
All of the characters in the associated output were successfully transferred[.](#4.2.sentence-1)
- [(4.3)](#4.3)
The call to *wrapped*->pubsync() (if any) succeeded[.](#4.3.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12836)
*Remarks*: May call member functions of *wrapped* while holding a lock uniquely associated with *wrapped*[.](#5.sentence-1)
[🔗](#lib:get_wrapped,basic_syncbuf)
`streambuf_type* get_wrapped() const noexcept;
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12848)
*Returns*: *wrapped*[.](#6.sentence-1)
[🔗](#lib:get_allocator,basic_syncbuf)
`allocator_type get_allocator() const noexcept;
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12859)
*Returns*: A copy of the allocator that was set in the constructor or assignment operator[.](#7.sentence-1)
[🔗](#lib:set_emit_on_sync,basic_syncbuf)
`void set_emit_on_sync(bool b) noexcept;
`
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12870)
*Effects*: *emit-on-sync* = b[.](#8.sentence-1)

View File

@@ -0,0 +1,32 @@
[syncstream.syncbuf.overview]
# 31 Input/output library [[input.output]](./#input.output)
## 31.11 Synchronized output streams [[syncstream]](syncstream#syncbuf.overview)
### 31.11.2 Class template basic_syncbuf [[syncstream.syncbuf]](syncstream.syncbuf#overview)
#### 31.11.2.1 Overview [syncstream.syncbuf.overview]
[🔗](#lib:basic_syncbuf)
namespace std {template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>class basic_syncbuf : public basic_streambuf<charT, traits> {public:using char_type = charT; using int_type = typename traits::int_type; using pos_type = typename traits::pos_type; using off_type = typename traits::off_type; using traits_type = traits; using allocator_type = Allocator; using streambuf_type = basic_streambuf<charT, traits>; // [[syncstream.syncbuf.cons]](syncstream.syncbuf.cons "31.11.2.2Construction and destruction"), construction and destruction basic_syncbuf(): basic_syncbuf(nullptr) {}explicit basic_syncbuf(streambuf_type* obuf): basic_syncbuf(obuf, Allocator()) {} basic_syncbuf(streambuf_type*, const Allocator&);
basic_syncbuf(basic_syncbuf&&); ~basic_syncbuf(); // [[syncstream.syncbuf.assign]](syncstream.syncbuf.assign "31.11.2.3Assignment and swap"), assignment and swap basic_syncbuf& operator=(basic_syncbuf&&); void swap(basic_syncbuf&); // [[syncstream.syncbuf.members]](syncstream.syncbuf.members "31.11.2.4Member functions"), member functionsbool emit();
streambuf_type* get_wrapped() const noexcept;
allocator_type get_allocator() const noexcept; void set_emit_on_sync(bool) noexcept; protected:// [[syncstream.syncbuf.virtuals]](syncstream.syncbuf.virtuals "31.11.2.5Overridden virtual functions"), overridden virtual functionsint sync() override; private: streambuf_type* *wrapped*; // *exposition only*bool *emit-on-sync*{}; // *exposition only*};}
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12649)
Class template basic_syncbuf stores character data
written to it, known as the associated output, into internal
buffers allocated using the object's allocator[.](#1.sentence-1)
The associated output is transferred to the
wrapped stream buffer object **wrapped* when emit() is called
or when the basic_syncbuf object is destroyed[.](#1.sentence-2)
Such transfers are atomic with respect to transfers
by other basic_syncbuf objects
with the same wrapped stream buffer object[.](#1.sentence-3)

View File

@@ -0,0 +1,22 @@
[syncstream.syncbuf.special]
# 31 Input/output library [[input.output]](./#input.output)
## 31.11 Synchronized output streams [[syncstream]](syncstream#syncbuf.special)
### 31.11.2 Class template basic_syncbuf [[syncstream.syncbuf]](syncstream.syncbuf#special)
#### 31.11.2.6 Specialized algorithms [syncstream.syncbuf.special]
[🔗](#lib:swap,basic_syncbuf)
`template<class charT, class traits, class Allocator>
void swap(basic_syncbuf<charT, traits, Allocator>& a,
basic_syncbuf<charT, traits, Allocator>& b);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12908)
*Effects*: Equivalent to a.swap(b)[.](#1.sentence-1)

View File

@@ -0,0 +1,36 @@
[syncstream.syncbuf.virtuals]
# 31 Input/output library [[input.output]](./#input.output)
## 31.11 Synchronized output streams [[syncstream]](syncstream#syncbuf.virtuals)
### 31.11.2 Class template basic_syncbuf [[syncstream.syncbuf]](syncstream.syncbuf#virtuals)
#### 31.11.2.5 Overridden virtual functions [syncstream.syncbuf.virtuals]
[🔗](#lib:sync,basic_syncbuf)
`int sync() override;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12883)
*Effects*: Records that the wrapped stream buffer is to be flushed[.](#1.sentence-1)
Then, if *emit-on-sync* is true, calls emit()[.](#1.sentence-2)
[*Note [1](#note-1)*:
If *emit-on-sync* is false,
the actual flush is delayed until a call to emit()[.](#1.sentence-3)
— *end note*]
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L12892)
*Returns*: If emit() was called and returned false,
returns -1; otherwise 0[.](#2.sentence-1)