tmp/tmp89x81lgk/{from.md → to.md}
RENAMED
|
@@ -4,10 +4,11 @@
|
|
| 4 |
|
| 5 |
``` cpp
|
| 6 |
#include <ostream> // see [ostream.syn]
|
| 7 |
|
| 8 |
namespace std {
|
|
|
|
| 9 |
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
|
| 10 |
class basic_syncbuf;
|
| 11 |
|
| 12 |
// [syncstream.syncbuf.special], specialized algorithms
|
| 13 |
template<class charT, class traits, class Allocator>
|
|
@@ -15,10 +16,11 @@ namespace std {
|
|
| 15 |
basic_syncbuf<charT, traits, Allocator>&);
|
| 16 |
|
| 17 |
using syncbuf = basic_syncbuf<char>;
|
| 18 |
using wsyncbuf = basic_syncbuf<wchar_t>;
|
| 19 |
|
|
|
|
| 20 |
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
|
| 21 |
class basic_osyncstream;
|
| 22 |
|
| 23 |
using osyncstream = basic_osyncstream<char>;
|
| 24 |
using wosyncstream = basic_osyncstream<wchar_t>;
|
|
@@ -36,13 +38,13 @@ agents writing to the same stream.
|
|
| 36 |
namespace std {
|
| 37 |
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
|
| 38 |
class basic_syncbuf : public basic_streambuf<charT, traits> {
|
| 39 |
public:
|
| 40 |
using char_type = charT;
|
| 41 |
-
using int_type =
|
| 42 |
-
using pos_type =
|
| 43 |
-
using off_type =
|
| 44 |
using traits_type = traits;
|
| 45 |
using allocator_type = Allocator;
|
| 46 |
|
| 47 |
using streambuf_type = basic_streambuf<charT, traits>;
|
| 48 |
|
|
@@ -69,11 +71,11 @@ namespace std {
|
|
| 69 |
// [syncstream.syncbuf.virtuals], overridden virtual functions
|
| 70 |
int sync() override;
|
| 71 |
|
| 72 |
private:
|
| 73 |
streambuf_type* wrapped; // exposition only
|
| 74 |
-
bool
|
| 75 |
};
|
| 76 |
}
|
| 77 |
```
|
| 78 |
|
| 79 |
Class template `basic_syncbuf` stores character data written to it,
|
|
@@ -88,11 +90,11 @@ wrapped stream buffer object.
|
|
| 88 |
|
| 89 |
``` cpp
|
| 90 |
basic_syncbuf(streambuf_type* obuf, const Allocator& allocator);
|
| 91 |
```
|
| 92 |
|
| 93 |
-
*Effects:* Sets
|
| 94 |
|
| 95 |
*Ensures:* `get_wrapped() == obuf` and `get_allocator() == allocator`
|
| 96 |
are `true`.
|
| 97 |
|
| 98 |
*Throws:* Nothing unless an exception is thrown by the construction of a
|
|
@@ -163,13 +165,13 @@ void swap(basic_syncbuf& other);
|
|
| 163 |
``` cpp
|
| 164 |
bool emit();
|
| 165 |
```
|
| 166 |
|
| 167 |
*Effects:* Atomically transfers the associated output of `*this` to the
|
| 168 |
-
stream buffer `*wrapped`, so that it appears in the output stream as
|
| 169 |
-
contiguous sequence of characters. `wrapped->pubsync()` is called
|
| 170 |
-
only if a call was made to `sync()` since the most recent call to
|
| 171 |
`emit()`, if any.
|
| 172 |
|
| 173 |
*Synchronization:* All `emit()` calls transferring characters to the
|
| 174 |
same stream buffer object appear to execute in a total order consistent
|
| 175 |
with the “happens before” relation [[intro.races]], where each `emit()`
|
|
@@ -178,23 +180,23 @@ call synchronizes with subsequent `emit()` calls in that total order.
|
|
| 178 |
*Ensures:* On success, the associated output is empty.
|
| 179 |
|
| 180 |
*Returns:* `true` if all of the following conditions hold; otherwise
|
| 181 |
`false`:
|
| 182 |
|
| 183 |
-
- `wrapped == nullptr` is `false`.
|
| 184 |
- All of the characters in the associated output were successfully
|
| 185 |
transferred.
|
| 186 |
-
- The call to `wrapped->pubsync()` (if any) succeeded.
|
| 187 |
|
| 188 |
-
*Remarks:* May call member functions of
|
| 189 |
-
uniquely associated with
|
| 190 |
|
| 191 |
``` cpp
|
| 192 |
streambuf_type* get_wrapped() const noexcept;
|
| 193 |
```
|
| 194 |
|
| 195 |
-
*Returns:*
|
| 196 |
|
| 197 |
``` cpp
|
| 198 |
allocator_type get_allocator() const noexcept;
|
| 199 |
```
|
| 200 |
|
|
@@ -203,22 +205,22 @@ assignment operator.
|
|
| 203 |
|
| 204 |
``` cpp
|
| 205 |
void set_emit_on_sync(bool b) noexcept;
|
| 206 |
```
|
| 207 |
|
| 208 |
-
*Effects:* `
|
| 209 |
|
| 210 |
#### Overridden virtual functions <a id="syncstream.syncbuf.virtuals">[[syncstream.syncbuf.virtuals]]</a>
|
| 211 |
|
| 212 |
``` cpp
|
| 213 |
int sync() override;
|
| 214 |
```
|
| 215 |
|
| 216 |
*Effects:* Records that the wrapped stream buffer is to be flushed.
|
| 217 |
-
Then, if
|
| 218 |
|
| 219 |
-
[*Note 1*: If
|
| 220 |
until a call to `emit()`. — *end note*]
|
| 221 |
|
| 222 |
*Returns:* If `emit()` was called and returned `false`, returns `-1`;
|
| 223 |
otherwise `0`.
|
| 224 |
|
|
@@ -240,13 +242,13 @@ template<class charT, class traits, class Allocator>
|
|
| 240 |
namespace std {
|
| 241 |
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
|
| 242 |
class basic_osyncstream : public basic_ostream<charT, traits> {
|
| 243 |
public:
|
| 244 |
using char_type = charT;
|
| 245 |
-
using int_type =
|
| 246 |
-
using pos_type =
|
| 247 |
-
using off_type =
|
| 248 |
using traits_type = traits;
|
| 249 |
|
| 250 |
using allocator_type = Allocator;
|
| 251 |
using streambuf_type = basic_streambuf<charT, traits>;
|
| 252 |
using syncbuf_type = basic_syncbuf<charT, traits, Allocator>;
|
|
@@ -311,12 +313,12 @@ In this example, `cout` is not flushed.
|
|
| 311 |
|
| 312 |
``` cpp
|
| 313 |
basic_osyncstream(streambuf_type* buf, const Allocator& allocator);
|
| 314 |
```
|
| 315 |
|
| 316 |
-
*Effects:* Initializes
|
| 317 |
-
base class with `basic_ostream<charT, traits>(addressof(sb))`.
|
| 318 |
|
| 319 |
[*Note 1*: The member functions of the provided stream buffer can be
|
| 320 |
called from `emit()` while a lock is held, which might result in a
|
| 321 |
deadlock if used incautiously. — *end note*]
|
| 322 |
|
|
@@ -324,13 +326,13 @@ deadlock if used incautiously. — *end note*]
|
|
| 324 |
|
| 325 |
``` cpp
|
| 326 |
basic_osyncstream(basic_osyncstream&& other) noexcept;
|
| 327 |
```
|
| 328 |
|
| 329 |
-
*Effects:* Move constructs the base class and
|
| 330 |
corresponding subobjects of `other`, and calls
|
| 331 |
-
`basic_ostream<charT, traits>::set_rdbuf(addressof(sb))`.
|
| 332 |
|
| 333 |
*Ensures:* The value returned by `get_wrapped()` is the value returned
|
| 334 |
by `other.get_wrapped()` prior to calling this constructor.
|
| 335 |
`nullptr == other.get_wrapped()` is `true`.
|
| 336 |
|
|
@@ -340,11 +342,11 @@ by `other.get_wrapped()` prior to calling this constructor.
|
|
| 340 |
void emit();
|
| 341 |
```
|
| 342 |
|
| 343 |
*Effects:* Behaves as an unformatted output
|
| 344 |
function [[ostream.unformatted]]. After constructing a `sentry` object,
|
| 345 |
-
calls `sb.emit()`. If that call returns `false`, calls
|
| 346 |
`setstate(ios_base::badbit)`.
|
| 347 |
|
| 348 |
[*Example 1*:
|
| 349 |
|
| 350 |
A flush on a `basic_osyncstream` does not flush immediately:
|
|
@@ -383,11 +385,11 @@ on the underlying stream.
|
|
| 383 |
|
| 384 |
``` cpp
|
| 385 |
streambuf_type* get_wrapped() const noexcept;
|
| 386 |
```
|
| 387 |
|
| 388 |
-
*Returns:* `sb.get_wrapped()`.
|
| 389 |
|
| 390 |
[*Example 3*:
|
| 391 |
|
| 392 |
Obtaining the wrapped stream buffer with `get_wrapped()` allows wrapping
|
| 393 |
it again with an `osyncstream`. For example,
|
|
|
|
| 4 |
|
| 5 |
``` cpp
|
| 6 |
#include <ostream> // see [ostream.syn]
|
| 7 |
|
| 8 |
namespace std {
|
| 9 |
+
// [syncstream.syncbuf], class template basic_syncbuf
|
| 10 |
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
|
| 11 |
class basic_syncbuf;
|
| 12 |
|
| 13 |
// [syncstream.syncbuf.special], specialized algorithms
|
| 14 |
template<class charT, class traits, class Allocator>
|
|
|
|
| 16 |
basic_syncbuf<charT, traits, Allocator>&);
|
| 17 |
|
| 18 |
using syncbuf = basic_syncbuf<char>;
|
| 19 |
using wsyncbuf = basic_syncbuf<wchar_t>;
|
| 20 |
|
| 21 |
+
// [syncstream.osyncstream], class template basic_osyncstream
|
| 22 |
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
|
| 23 |
class basic_osyncstream;
|
| 24 |
|
| 25 |
using osyncstream = basic_osyncstream<char>;
|
| 26 |
using wosyncstream = basic_osyncstream<wchar_t>;
|
|
|
|
| 38 |
namespace std {
|
| 39 |
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
|
| 40 |
class basic_syncbuf : public basic_streambuf<charT, traits> {
|
| 41 |
public:
|
| 42 |
using char_type = charT;
|
| 43 |
+
using int_type = traits::int_type;
|
| 44 |
+
using pos_type = traits::pos_type;
|
| 45 |
+
using off_type = traits::off_type;
|
| 46 |
using traits_type = traits;
|
| 47 |
using allocator_type = Allocator;
|
| 48 |
|
| 49 |
using streambuf_type = basic_streambuf<charT, traits>;
|
| 50 |
|
|
|
|
| 71 |
// [syncstream.syncbuf.virtuals], overridden virtual functions
|
| 72 |
int sync() override;
|
| 73 |
|
| 74 |
private:
|
| 75 |
streambuf_type* wrapped; // exposition only
|
| 76 |
+
bool emit-on-sync{}; // exposition only
|
| 77 |
};
|
| 78 |
}
|
| 79 |
```
|
| 80 |
|
| 81 |
Class template `basic_syncbuf` stores character data written to it,
|
|
|
|
| 90 |
|
| 91 |
``` cpp
|
| 92 |
basic_syncbuf(streambuf_type* obuf, const Allocator& allocator);
|
| 93 |
```
|
| 94 |
|
| 95 |
+
*Effects:* Sets *wrapped* to `obuf`.
|
| 96 |
|
| 97 |
*Ensures:* `get_wrapped() == obuf` and `get_allocator() == allocator`
|
| 98 |
are `true`.
|
| 99 |
|
| 100 |
*Throws:* Nothing unless an exception is thrown by the construction of a
|
|
|
|
| 165 |
``` cpp
|
| 166 |
bool emit();
|
| 167 |
```
|
| 168 |
|
| 169 |
*Effects:* Atomically transfers the associated output of `*this` to the
|
| 170 |
+
stream buffer `*`*`wrapped`*, so that it appears in the output stream as
|
| 171 |
+
a contiguous sequence of characters. *`wrapped`*`->pubsync()` is called
|
| 172 |
+
if and only if a call was made to `sync()` since the most recent call to
|
| 173 |
`emit()`, if any.
|
| 174 |
|
| 175 |
*Synchronization:* All `emit()` calls transferring characters to the
|
| 176 |
same stream buffer object appear to execute in a total order consistent
|
| 177 |
with the “happens before” relation [[intro.races]], where each `emit()`
|
|
|
|
| 180 |
*Ensures:* On success, the associated output is empty.
|
| 181 |
|
| 182 |
*Returns:* `true` if all of the following conditions hold; otherwise
|
| 183 |
`false`:
|
| 184 |
|
| 185 |
+
- *`wrapped`*` == nullptr` is `false`.
|
| 186 |
- All of the characters in the associated output were successfully
|
| 187 |
transferred.
|
| 188 |
+
- The call to *`wrapped`*`->pubsync()` (if any) succeeded.
|
| 189 |
|
| 190 |
+
*Remarks:* May call member functions of *wrapped* while holding a lock
|
| 191 |
+
uniquely associated with *wrapped*.
|
| 192 |
|
| 193 |
``` cpp
|
| 194 |
streambuf_type* get_wrapped() const noexcept;
|
| 195 |
```
|
| 196 |
|
| 197 |
+
*Returns:* *wrapped*.
|
| 198 |
|
| 199 |
``` cpp
|
| 200 |
allocator_type get_allocator() const noexcept;
|
| 201 |
```
|
| 202 |
|
|
|
|
| 205 |
|
| 206 |
``` cpp
|
| 207 |
void set_emit_on_sync(bool b) noexcept;
|
| 208 |
```
|
| 209 |
|
| 210 |
+
*Effects:* *`emit-on-sync`*` = b`.
|
| 211 |
|
| 212 |
#### Overridden virtual functions <a id="syncstream.syncbuf.virtuals">[[syncstream.syncbuf.virtuals]]</a>
|
| 213 |
|
| 214 |
``` cpp
|
| 215 |
int sync() override;
|
| 216 |
```
|
| 217 |
|
| 218 |
*Effects:* Records that the wrapped stream buffer is to be flushed.
|
| 219 |
+
Then, if *emit-on-sync* is `true`, calls `emit()`.
|
| 220 |
|
| 221 |
+
[*Note 1*: If *emit-on-sync* is `false`, the actual flush is delayed
|
| 222 |
until a call to `emit()`. — *end note*]
|
| 223 |
|
| 224 |
*Returns:* If `emit()` was called and returned `false`, returns `-1`;
|
| 225 |
otherwise `0`.
|
| 226 |
|
|
|
|
| 242 |
namespace std {
|
| 243 |
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
|
| 244 |
class basic_osyncstream : public basic_ostream<charT, traits> {
|
| 245 |
public:
|
| 246 |
using char_type = charT;
|
| 247 |
+
using int_type = traits::int_type;
|
| 248 |
+
using pos_type = traits::pos_type;
|
| 249 |
+
using off_type = traits::off_type;
|
| 250 |
using traits_type = traits;
|
| 251 |
|
| 252 |
using allocator_type = Allocator;
|
| 253 |
using streambuf_type = basic_streambuf<charT, traits>;
|
| 254 |
using syncbuf_type = basic_syncbuf<charT, traits, Allocator>;
|
|
|
|
| 313 |
|
| 314 |
``` cpp
|
| 315 |
basic_osyncstream(streambuf_type* buf, const Allocator& allocator);
|
| 316 |
```
|
| 317 |
|
| 318 |
+
*Effects:* Initializes *sb* from `buf` and `allocator`. Initializes the
|
| 319 |
+
base class with `basic_ostream<charT, traits>(addressof(`*`sb`*`))`.
|
| 320 |
|
| 321 |
[*Note 1*: The member functions of the provided stream buffer can be
|
| 322 |
called from `emit()` while a lock is held, which might result in a
|
| 323 |
deadlock if used incautiously. — *end note*]
|
| 324 |
|
|
|
|
| 326 |
|
| 327 |
``` cpp
|
| 328 |
basic_osyncstream(basic_osyncstream&& other) noexcept;
|
| 329 |
```
|
| 330 |
|
| 331 |
+
*Effects:* Move constructs the base class and *sb* from the
|
| 332 |
corresponding subobjects of `other`, and calls
|
| 333 |
+
`basic_ostream<charT, traits>::set_rdbuf(addressof(`*`sb`*`))`.
|
| 334 |
|
| 335 |
*Ensures:* The value returned by `get_wrapped()` is the value returned
|
| 336 |
by `other.get_wrapped()` prior to calling this constructor.
|
| 337 |
`nullptr == other.get_wrapped()` is `true`.
|
| 338 |
|
|
|
|
| 342 |
void emit();
|
| 343 |
```
|
| 344 |
|
| 345 |
*Effects:* Behaves as an unformatted output
|
| 346 |
function [[ostream.unformatted]]. After constructing a `sentry` object,
|
| 347 |
+
calls *`sb`*`.emit()`. If that call returns `false`, calls
|
| 348 |
`setstate(ios_base::badbit)`.
|
| 349 |
|
| 350 |
[*Example 1*:
|
| 351 |
|
| 352 |
A flush on a `basic_osyncstream` does not flush immediately:
|
|
|
|
| 385 |
|
| 386 |
``` cpp
|
| 387 |
streambuf_type* get_wrapped() const noexcept;
|
| 388 |
```
|
| 389 |
|
| 390 |
+
*Returns:* *`sb`*`.get_wrapped()`.
|
| 391 |
|
| 392 |
[*Example 3*:
|
| 393 |
|
| 394 |
Obtaining the wrapped stream buffer with `get_wrapped()` allows wrapping
|
| 395 |
it again with an `osyncstream`. For example,
|