From Jason Turner

[syncstream.syncbuf]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpspkgbnv7/{from.md → to.md} +210 -0
tmp/tmpspkgbnv7/{from.md → to.md} RENAMED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Class template `basic_syncbuf` <a id="syncstream.syncbuf">[[syncstream.syncbuf]]</a>
2
+
3
+ #### Overview <a id="syncstream.syncbuf.overview">[[syncstream.syncbuf.overview]]</a>
4
+
5
+ ``` cpp
6
+ namespace std {
7
+ template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
8
+ class basic_syncbuf : public basic_streambuf<charT, traits> {
9
+ public:
10
+ using char_type = charT;
11
+ using int_type = typename traits::int_type;
12
+ using pos_type = typename traits::pos_type;
13
+ using off_type = typename traits::off_type;
14
+ using traits_type = traits;
15
+ using allocator_type = Allocator;
16
+
17
+ using streambuf_type = basic_streambuf<charT, traits>;
18
+
19
+ // [syncstream.syncbuf.cons], construction and destruction
20
+ basic_syncbuf()
21
+ : basic_syncbuf(nullptr) {}
22
+ explicit basic_syncbuf(streambuf_type* obuf)
23
+ : basic_syncbuf(obuf, Allocator()) {}
24
+ basic_syncbuf(streambuf_type*, const Allocator&);
25
+ basic_syncbuf(basic_syncbuf&&);
26
+ ~basic_syncbuf();
27
+
28
+ // [syncstream.syncbuf.assign], assignment and swap
29
+ basic_syncbuf& operator=(basic_syncbuf&&);
30
+ void swap(basic_syncbuf&);
31
+
32
+ // [syncstream.syncbuf.members], member functions
33
+ bool emit();
34
+ streambuf_type* get_wrapped() const noexcept;
35
+ allocator_type get_allocator() const noexcept;
36
+ void set_emit_on_sync(bool) noexcept;
37
+
38
+ protected:
39
+ // [syncstream.syncbuf.virtuals], overridden virtual functions
40
+ int sync() override;
41
+
42
+ private:
43
+ streambuf_type* wrapped; // exposition only
44
+ bool emit_on_sync{}; // exposition only
45
+ };
46
+
47
+ // [syncstream.syncbuf.special], specialized algorithms
48
+ template<class charT, class traits, class Allocator>
49
+ void swap(basic_syncbuf<charT, traits, Allocator>&,
50
+ basic_syncbuf<charT, traits, Allocator>&);
51
+ }
52
+ ```
53
+
54
+ Class template `basic_syncbuf` stores character data written to it,
55
+ known as the associated output, into internal buffers allocated using
56
+ the object’s allocator. The associated output is transferred to the
57
+ wrapped stream buffer object `*wrapped` when `emit()` is called or when
58
+ the `basic_syncbuf` object is destroyed. Such transfers are atomic with
59
+ respect to transfers by other `basic_syncbuf` objects with the same
60
+ wrapped stream buffer object.
61
+
62
+ #### Construction and destruction <a id="syncstream.syncbuf.cons">[[syncstream.syncbuf.cons]]</a>
63
+
64
+ ``` cpp
65
+ basic_syncbuf(streambuf_type* obuf, const Allocator& allocator);
66
+ ```
67
+
68
+ *Effects:* Sets `wrapped` to `obuf`.
69
+
70
+ *Remarks:* A copy of `allocator` is used to allocate memory for internal
71
+ buffers holding the associated output.
72
+
73
+ *Throws:* Nothing unless an exception is thrown by the construction of a
74
+ mutex or by memory allocation.
75
+
76
+ *Ensures:* `get_wrapped() == obuf` and `get_allocator() == allocator`
77
+ are `true`.
78
+
79
+ ``` cpp
80
+ basic_syncbuf(basic_syncbuf&& other);
81
+ ```
82
+
83
+ *Ensures:* The value returned by `this->get_wrapped()` is the value
84
+ returned by `other.get_wrapped()` prior to calling this constructor.
85
+ Output stored in `other` prior to calling this constructor will be
86
+ stored in `*this` afterwards.
87
+ `other.rdbuf()->pbase() == other.rdbuf()->pptr()` and
88
+ `other.get_wrapped() == nullptr` are `true`.
89
+
90
+ *Remarks:* This constructor disassociates `other` from its wrapped
91
+ stream buffer, ensuring destruction of `other` produces no output.
92
+
93
+ ``` cpp
94
+ ~basic_syncbuf();
95
+ ```
96
+
97
+ *Effects:* Calls `emit()`.
98
+
99
+ *Throws:* Nothing. If an exception is thrown from `emit()`, the
100
+ destructor catches and ignores that exception.
101
+
102
+ #### Assignment and swap <a id="syncstream.syncbuf.assign">[[syncstream.syncbuf.assign]]</a>
103
+
104
+ ``` cpp
105
+ basic_syncbuf& operator=(basic_syncbuf&& rhs) noexcept;
106
+ ```
107
+
108
+ *Effects:* Calls `emit()` then move assigns from `rhs`. After the move
109
+ assignment `*this` has the observable state it would have had if it had
110
+ been move constructed from `rhs` [[syncstream.syncbuf.cons]].
111
+
112
+ *Returns:* `*this`.
113
+
114
+ *Ensures:*
115
+
116
+ - `rhs.get_wrapped() == nullptr` is `true`.
117
+ - `this->get_allocator() == rhs.get_allocator()` is `true` when
118
+ ``` cpp
119
+ allocator_traits<Allocator>::propagate_on_container_move_assignment::value
120
+ ```
121
+
122
+ is `true`; otherwise, the allocator is unchanged.
123
+
124
+ *Remarks:* This assignment operator disassociates `rhs` from its wrapped
125
+ stream buffer, ensuring destruction of `rhs` produces no output.
126
+
127
+ ``` cpp
128
+ void swap(basic_syncbuf& other) noexcept;
129
+ ```
130
+
131
+ *Preconditions:* Either
132
+ `allocator_traits<Allocator>::propagate_on_container_swap::value` is
133
+ `true` or `this->get_allocator() == other.get_allocator()` is `true`.
134
+
135
+ *Effects:* Exchanges the state of `*this` and `other`.
136
+
137
+ #### Member functions <a id="syncstream.syncbuf.members">[[syncstream.syncbuf.members]]</a>
138
+
139
+ ``` cpp
140
+ bool emit();
141
+ ```
142
+
143
+ *Effects:* Atomically transfers the associated output of `*this` to the
144
+ stream buffer `*wrapped`, so that it appears in the output stream as a
145
+ contiguous sequence of characters. `wrapped->pubsync()` is called if and
146
+ only if a call was made to `sync()` since the most recent call to
147
+ `emit()`, if any.
148
+
149
+ *Returns:* `true` if all of the following conditions hold; otherwise
150
+ `false`:
151
+
152
+ - `wrapped == nullptr` is `false`.
153
+ - All of the characters in the associated output were successfully
154
+ transferred.
155
+ - The call to `wrapped->pubsync()` (if any) succeeded.
156
+
157
+ *Ensures:* On success, the associated output is empty.
158
+
159
+ *Synchronization:* All `emit()` calls transferring characters to the
160
+ same stream buffer object appear to execute in a total order consistent
161
+ with the “happens before” relation [[intro.races]], where each `emit()`
162
+ call synchronizes with subsequent `emit()` calls in that total order.
163
+
164
+ *Remarks:* May call member functions of `wrapped` while holding a lock
165
+ uniquely associated with `wrapped`.
166
+
167
+ ``` cpp
168
+ streambuf_type* get_wrapped() const noexcept;
169
+ ```
170
+
171
+ *Returns:* `wrapped`.
172
+
173
+ ``` cpp
174
+ allocator_type get_allocator() const noexcept;
175
+ ```
176
+
177
+ *Returns:* A copy of the allocator that was set in the constructor or
178
+ assignment operator.
179
+
180
+ ``` cpp
181
+ void set_emit_on_sync(bool b) noexcept;
182
+ ```
183
+
184
+ *Effects:* `emit_on_sync = b`.
185
+
186
+ #### Overridden virtual functions <a id="syncstream.syncbuf.virtuals">[[syncstream.syncbuf.virtuals]]</a>
187
+
188
+ ``` cpp
189
+ int sync() override;
190
+ ```
191
+
192
+ *Effects:* Records that the wrapped stream buffer is to be flushed.
193
+ Then, if `emit_on_sync` is `true`, calls `emit()`.
194
+
195
+ [*Note 1*: If `emit_on_sync` is `false`, the actual flush is delayed
196
+ until a call to `emit()`. — *end note*]
197
+
198
+ *Returns:* If `emit()` was called and returned `false`, returns `-1`;
199
+ otherwise `0`.
200
+
201
+ #### Specialized algorithms <a id="syncstream.syncbuf.special">[[syncstream.syncbuf.special]]</a>
202
+
203
+ ``` cpp
204
+ template<class charT, class traits, class Allocator>
205
+ void swap(basic_syncbuf<charT, traits, Allocator>& a,
206
+ basic_syncbuf<charT, traits, Allocator>& b) noexcept;
207
+ ```
208
+
209
+ *Effects:* Equivalent to `a.swap(b)`.
210
+