- tmp/tmpolldv5gr/{from.md → to.md} +659 -186
tmp/tmpolldv5gr/{from.md → to.md}
RENAMED
|
@@ -50,26 +50,55 @@ namespace std {
|
|
| 50 |
using off_type = typename traits::off_type;
|
| 51 |
using traits_type = traits;
|
| 52 |
using allocator_type = Allocator;
|
| 53 |
|
| 54 |
// [stringbuf.cons], constructors
|
|
|
|
|
|
|
| 55 |
explicit basic_stringbuf(
|
|
|
|
| 56 |
ios_base::openmode which = ios_base::in | ios_base::out);
|
|
|
|
|
|
|
|
|
|
| 57 |
explicit basic_stringbuf(
|
| 58 |
-
|
| 59 |
ios_base::openmode which = ios_base::in | ios_base::out);
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
basic_stringbuf(basic_stringbuf&& rhs);
|
|
|
|
| 62 |
|
| 63 |
// [stringbuf.assign], assign and swap
|
| 64 |
-
basic_stringbuf& operator=(const basic_stringbuf&
|
| 65 |
basic_stringbuf& operator=(basic_stringbuf&& rhs);
|
| 66 |
-
void swap(basic_stringbuf& rhs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
// [stringbuf.members], get and set
|
| 69 |
-
basic_string<charT, traits, Allocator> str() const;
|
| 70 |
void str(const basic_string<charT, traits, Allocator>& s);
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
protected:
|
| 73 |
// [stringbuf.virtuals], overridden virtual functions
|
| 74 |
int_type underflow() override;
|
| 75 |
int_type pbackfail(int_type c = traits::eof()) override;
|
|
@@ -83,66 +112,120 @@ namespace std {
|
|
| 83 |
ios_base::openmode which
|
| 84 |
= ios_base::in | ios_base::out) override;
|
| 85 |
|
| 86 |
private:
|
| 87 |
ios_base::openmode mode; // exposition only
|
|
|
|
|
|
|
| 88 |
};
|
| 89 |
|
| 90 |
template<class charT, class traits, class Allocator>
|
| 91 |
void swap(basic_stringbuf<charT, traits, Allocator>& x,
|
| 92 |
-
basic_stringbuf<charT, traits, Allocator>& y);
|
| 93 |
}
|
| 94 |
```
|
| 95 |
|
| 96 |
The class `basic_stringbuf` is derived from `basic_streambuf` to
|
| 97 |
associate possibly the input sequence and possibly the output sequence
|
| 98 |
with a sequence of arbitrary *characters*. The sequence can be
|
| 99 |
initialized from, or made available as, an object of class
|
| 100 |
`basic_string`.
|
| 101 |
|
| 102 |
-
For the sake of exposition, the maintained data
|
|
|
|
| 103 |
|
| 104 |
- `ios_base::openmode mode`, has `in` set if the input sequence can be
|
| 105 |
read, and `out` set if the output sequence can be written.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
-
####
|
| 108 |
|
| 109 |
``` cpp
|
| 110 |
-
explicit basic_stringbuf(
|
| 111 |
-
ios_base::openmode which = ios_base::in | ios_base::out);
|
| 112 |
```
|
| 113 |
|
| 114 |
-
*Effects:*
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
| 117 |
|
| 118 |
-
*
|
| 119 |
|
| 120 |
``` cpp
|
| 121 |
explicit basic_stringbuf(
|
| 122 |
const basic_string<charT, traits, Allocator>& s,
|
| 123 |
ios_base::openmode which = ios_base::in | ios_base::out);
|
| 124 |
```
|
| 125 |
|
| 126 |
-
*Effects:*
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
``` cpp
|
| 131 |
basic_stringbuf(basic_stringbuf&& rhs);
|
|
|
|
| 132 |
```
|
| 133 |
|
| 134 |
-
*Effects:*
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
|
| 141 |
-
*
|
| 142 |
-
|
| 143 |
-
|
| 144 |
|
| 145 |
- `str() == rhs_p.str()`
|
| 146 |
- `gptr() - eback() == rhs_p.gptr() - rhs_p.eback()`
|
| 147 |
- `egptr() - eback() == rhs_p.egptr() - rhs_p.eback()`
|
| 148 |
- `pptr() - pbase() == rhs_p.pptr() - rhs_p.pbase()`
|
|
@@ -151,12 +234,14 @@ this construction.
|
|
| 151 |
- `if (gptr()) gptr() != rhs_a.gptr()`
|
| 152 |
- `if (egptr()) egptr() != rhs_a.egptr()`
|
| 153 |
- `if (pbase()) pbase() != rhs_a.pbase()`
|
| 154 |
- `if (pptr()) pptr() != rhs_a.pptr()`
|
| 155 |
- `if (epptr()) epptr() != rhs_a.epptr()`
|
|
|
|
|
|
|
| 156 |
|
| 157 |
-
####
|
| 158 |
|
| 159 |
``` cpp
|
| 160 |
basic_stringbuf& operator=(basic_stringbuf&& rhs);
|
| 161 |
```
|
| 162 |
|
|
@@ -165,62 +250,165 @@ would have had if it had been move constructed from `rhs`
|
|
| 165 |
(see [[stringbuf.cons]]).
|
| 166 |
|
| 167 |
*Returns:* `*this`.
|
| 168 |
|
| 169 |
``` cpp
|
| 170 |
-
void swap(basic_stringbuf& rhs);
|
| 171 |
```
|
| 172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
*Effects:* Exchanges the state of `*this` and `rhs`.
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
``` cpp
|
| 176 |
template<class charT, class traits, class Allocator>
|
| 177 |
void swap(basic_stringbuf<charT, traits, Allocator>& x,
|
| 178 |
-
basic_stringbuf<charT, traits, Allocator>& y);
|
| 179 |
```
|
| 180 |
|
| 181 |
-
*Effects:*
|
| 182 |
|
| 183 |
#### Member functions <a id="stringbuf.members">[[stringbuf.members]]</a>
|
| 184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
``` cpp
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
`
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
`
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
`basic_string
|
| 204 |
-
|
| 205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
|
| 207 |
``` cpp
|
| 208 |
void str(const basic_string<charT, traits, Allocator>& s);
|
| 209 |
```
|
| 210 |
|
| 211 |
-
*Effects:*
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
`
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
|
| 223 |
#### Overridden virtual functions <a id="stringbuf.virtuals">[[stringbuf.virtuals]]</a>
|
| 224 |
|
| 225 |
``` cpp
|
| 226 |
int_type underflow() override;
|
|
@@ -247,11 +435,11 @@ sequence, if possible, in one of three ways:
|
|
| 247 |
`ios_base::out` is nonzero, assigns `c` to `*``gptr()`. Returns: `c`.
|
| 248 |
- If `traits::eq_int_type(c, traits::eof())` returns `true` and if the
|
| 249 |
input sequence has a putback position available, assigns `gptr() - 1`
|
| 250 |
to `gptr()`. Returns: `traits::not_eof(c)`.
|
| 251 |
|
| 252 |
-
*Returns:* `traits::eof()` to indicate failure.
|
| 253 |
|
| 254 |
*Remarks:* If the function can succeed in more than one of these ways,
|
| 255 |
it is unspecified which way is chosen.
|
| 256 |
|
| 257 |
``` cpp
|
|
@@ -270,56 +458,55 @@ sequence, if possible, in one of two ways:
|
|
| 270 |
`traits::eof()`.
|
| 271 |
|
| 272 |
*Remarks:* The function can alter the number of write positions
|
| 273 |
available as a result of any call.
|
| 274 |
|
| 275 |
-
*Returns:* `traits::eof()` to indicate failure.
|
| 276 |
|
| 277 |
-
The function can make a write position available only if
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
|
| 285 |
``` cpp
|
| 286 |
pos_type seekoff(off_type off, ios_base::seekdir way,
|
| 287 |
ios_base::openmode which
|
| 288 |
= ios_base::in | ios_base::out) override;
|
| 289 |
```
|
| 290 |
|
| 291 |
*Effects:* Alters the stream position within one of the controlled
|
| 292 |
-
sequences, if possible, as indicated in
|
| 293 |
-
Table [[tab:iostreams.seekoff.positioning]].
|
| 294 |
|
| 295 |
-
**Table: `seekoff` positioning** <a id="
|
| 296 |
|
| 297 |
| Conditions | Result |
|
| 298 |
-
| ------------------------------------------------------------------------------------------------------------------------------
|
| 299 |
-
| `
|
| 300 |
-
| `
|
| 301 |
-
|
|
| 302 |
| Otherwise | the positioning operation fails. |
|
| 303 |
|
| 304 |
|
| 305 |
-
For a sequence to be positioned,
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
|
| 310 |
-
**Table: `newoff` values** <a id="
|
| 311 |
|
| 312 |
| Condition | `newoff` Value |
|
| 313 |
| ---------------------- | ----------------------------------------------------------------------- |
|
| 314 |
| `way == ios_base::beg` | 0 |
|
| 315 |
| `way == ios_base::cur` | the next pointer minus the beginning pointer (`xnext - xbeg`). |
|
| 316 |
| `way == ios_base::end` | the high mark pointer minus the beginning pointer (`high_mark - xbeg`). |
|
| 317 |
|
| 318 |
|
| 319 |
If `(newoff + off) < 0`, or if `newoff + off` refers to an uninitialized
|
| 320 |
-
character
|
| 321 |
Otherwise, the function assigns `xbeg + newoff + off` to the next
|
| 322 |
pointer `xnext`.
|
| 323 |
|
| 324 |
*Returns:* `pos_type(newoff)`, constructed from the resultant offset
|
| 325 |
`newoff` (of type `off_type`), that stores the resultant stream
|
|
@@ -361,28 +548,52 @@ namespace std {
|
|
| 361 |
using off_type = typename traits::off_type;
|
| 362 |
using traits_type = traits;
|
| 363 |
using allocator_type = Allocator;
|
| 364 |
|
| 365 |
// [istringstream.cons], constructors
|
|
|
|
|
|
|
| 366 |
explicit basic_istringstream(
|
|
|
|
| 367 |
ios_base::openmode which = ios_base::in);
|
|
|
|
| 368 |
explicit basic_istringstream(
|
| 369 |
-
|
| 370 |
ios_base::openmode which = ios_base::in);
|
| 371 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
basic_istringstream(basic_istringstream&& rhs);
|
| 373 |
|
| 374 |
// [istringstream.assign], assign and swap
|
| 375 |
-
basic_istringstream& operator=(const basic_istringstream&
|
| 376 |
basic_istringstream& operator=(basic_istringstream&& rhs);
|
| 377 |
void swap(basic_istringstream& rhs);
|
| 378 |
|
| 379 |
// [istringstream.members], members
|
| 380 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
|
| 382 |
-
basic_string<charT, traits, Allocator> str() const;
|
| 383 |
void str(const basic_string<charT, traits, Allocator>& s);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
private:
|
| 385 |
basic_stringbuf<charT, traits, Allocator> sb; // exposition only
|
| 386 |
};
|
| 387 |
|
| 388 |
template<class charT, class traits, class Allocator>
|
|
@@ -397,87 +608,157 @@ uses a `basic_stringbuf<charT, traits, Allocator>` object to control the
|
|
| 397 |
associated storage. For the sake of exposition, the maintained data is
|
| 398 |
presented here as:
|
| 399 |
|
| 400 |
- `sb`, the `stringbuf` object.
|
| 401 |
|
| 402 |
-
####
|
| 403 |
|
| 404 |
``` cpp
|
| 405 |
-
explicit basic_istringstream(ios_base::openmode which
|
| 406 |
```
|
| 407 |
|
| 408 |
-
*Effects:*
|
| 409 |
-
`
|
| 410 |
-
`
|
| 411 |
-
|
| 412 |
|
| 413 |
``` cpp
|
| 414 |
explicit basic_istringstream(
|
| 415 |
-
const basic_string<charT, traits, Allocator>&
|
| 416 |
ios_base::openmode which = ios_base::in);
|
| 417 |
```
|
| 418 |
|
| 419 |
-
*Effects:*
|
| 420 |
-
`
|
| 421 |
-
`
|
| 422 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 423 |
|
| 424 |
``` cpp
|
| 425 |
basic_istringstream(basic_istringstream&& rhs);
|
| 426 |
```
|
| 427 |
|
| 428 |
*Effects:* Move constructs from the rvalue `rhs`. This is accomplished
|
| 429 |
by move constructing the base class, and the contained
|
| 430 |
-
`basic_stringbuf`.
|
| 431 |
-
|
|
|
|
| 432 |
|
| 433 |
-
####
|
| 434 |
-
|
| 435 |
-
``` cpp
|
| 436 |
-
basic_istringstream& operator=(basic_istringstream&& rhs);
|
| 437 |
-
```
|
| 438 |
-
|
| 439 |
-
*Effects:* Move assigns the base and members of `*this` from the base
|
| 440 |
-
and corresponding members of `rhs`.
|
| 441 |
-
|
| 442 |
-
*Returns:* `*this`.
|
| 443 |
|
| 444 |
``` cpp
|
| 445 |
void swap(basic_istringstream& rhs);
|
| 446 |
```
|
| 447 |
|
| 448 |
-
*Effects:*
|
| 449 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 450 |
|
| 451 |
``` cpp
|
| 452 |
template<class charT, class traits, class Allocator>
|
| 453 |
void swap(basic_istringstream<charT, traits, Allocator>& x,
|
| 454 |
basic_istringstream<charT, traits, Allocator>& y);
|
| 455 |
```
|
| 456 |
|
| 457 |
-
*Effects:*
|
| 458 |
|
| 459 |
#### Member functions <a id="istringstream.members">[[istringstream.members]]</a>
|
| 460 |
|
| 461 |
``` cpp
|
| 462 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 463 |
```
|
| 464 |
|
| 465 |
*Returns:*
|
| 466 |
-
`const_cast<basic_stringbuf<charT, traits, Allocator>*>(
|
| 467 |
|
| 468 |
``` cpp
|
| 469 |
-
basic_string<charT, traits, Allocator> str() const;
|
| 470 |
```
|
| 471 |
|
| 472 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
|
| 474 |
``` cpp
|
| 475 |
void str(const basic_string<charT, traits, Allocator>& s);
|
| 476 |
```
|
| 477 |
|
| 478 |
-
*Effects:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 479 |
|
| 480 |
### Class template `basic_ostringstream` <a id="ostringstream">[[ostringstream]]</a>
|
| 481 |
|
| 482 |
``` cpp
|
| 483 |
namespace std {
|
|
@@ -491,28 +772,53 @@ namespace std {
|
|
| 491 |
using off_type = typename traits::off_type;
|
| 492 |
using traits_type = traits;
|
| 493 |
using allocator_type = Allocator;
|
| 494 |
|
| 495 |
// [ostringstream.cons], constructors
|
|
|
|
|
|
|
| 496 |
explicit basic_ostringstream(
|
|
|
|
| 497 |
ios_base::openmode which = ios_base::out);
|
|
|
|
| 498 |
explicit basic_ostringstream(
|
| 499 |
-
|
| 500 |
ios_base::openmode which = ios_base::out);
|
| 501 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 502 |
basic_ostringstream(basic_ostringstream&& rhs);
|
| 503 |
|
| 504 |
// [ostringstream.assign], assign and swap
|
| 505 |
-
basic_ostringstream& operator=(const basic_ostringstream&
|
| 506 |
basic_ostringstream& operator=(basic_ostringstream&& rhs);
|
| 507 |
void swap(basic_ostringstream& rhs);
|
| 508 |
|
| 509 |
// [ostringstream.members], members
|
| 510 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 511 |
|
| 512 |
-
basic_string<charT, traits, Allocator> str() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 513 |
void str(const basic_string<charT, traits, Allocator>& s);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
private:
|
| 515 |
basic_stringbuf<charT, traits, Allocator> sb; // exposition only
|
| 516 |
};
|
| 517 |
|
| 518 |
template<class charT, class traits, class Allocator>
|
|
@@ -526,88 +832,157 @@ writing objects of class `basic_string<{}charT, traits, Allocator>`. It
|
|
| 526 |
uses a `basic_stringbuf` object to control the associated storage. For
|
| 527 |
the sake of exposition, the maintained data is presented here as:
|
| 528 |
|
| 529 |
- `sb`, the `stringbuf` object.
|
| 530 |
|
| 531 |
-
####
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 532 |
|
| 533 |
``` cpp
|
| 534 |
explicit basic_ostringstream(
|
|
|
|
| 535 |
ios_base::openmode which = ios_base::out);
|
| 536 |
```
|
| 537 |
|
| 538 |
-
*Effects:*
|
| 539 |
-
|
| 540 |
-
`
|
| 541 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 542 |
|
| 543 |
``` cpp
|
| 544 |
explicit basic_ostringstream(
|
| 545 |
-
|
| 546 |
ios_base::openmode which = ios_base::out);
|
| 547 |
```
|
| 548 |
|
| 549 |
-
*Effects:*
|
| 550 |
-
`
|
| 551 |
-
`
|
| 552 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 553 |
|
| 554 |
``` cpp
|
| 555 |
basic_ostringstream(basic_ostringstream&& rhs);
|
| 556 |
```
|
| 557 |
|
| 558 |
*Effects:* Move constructs from the rvalue `rhs`. This is accomplished
|
| 559 |
by move constructing the base class, and the contained
|
| 560 |
-
`basic_stringbuf`.
|
| 561 |
-
|
|
|
|
| 562 |
|
| 563 |
-
####
|
| 564 |
-
|
| 565 |
-
``` cpp
|
| 566 |
-
basic_ostringstream& operator=(basic_ostringstream&& rhs);
|
| 567 |
-
```
|
| 568 |
-
|
| 569 |
-
*Effects:* Move assigns the base and members of `*this` from the base
|
| 570 |
-
and corresponding members of `rhs`.
|
| 571 |
-
|
| 572 |
-
*Returns:* `*this`.
|
| 573 |
|
| 574 |
``` cpp
|
| 575 |
void swap(basic_ostringstream& rhs);
|
| 576 |
```
|
| 577 |
|
| 578 |
-
*Effects:*
|
| 579 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 580 |
|
| 581 |
``` cpp
|
| 582 |
template<class charT, class traits, class Allocator>
|
| 583 |
void swap(basic_ostringstream<charT, traits, Allocator>& x,
|
| 584 |
basic_ostringstream<charT, traits, Allocator>& y);
|
| 585 |
```
|
| 586 |
|
| 587 |
-
*Effects:*
|
| 588 |
|
| 589 |
#### Member functions <a id="ostringstream.members">[[ostringstream.members]]</a>
|
| 590 |
|
| 591 |
``` cpp
|
| 592 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 593 |
```
|
| 594 |
|
| 595 |
*Returns:*
|
| 596 |
-
`const_cast<basic_stringbuf<charT, traits, Allocator>*>(
|
| 597 |
|
| 598 |
``` cpp
|
| 599 |
-
basic_string<charT, traits, Allocator> str() const;
|
| 600 |
```
|
| 601 |
|
| 602 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 603 |
|
| 604 |
``` cpp
|
| 605 |
void str(const basic_string<charT, traits, Allocator>& s);
|
| 606 |
```
|
| 607 |
|
| 608 |
-
*Effects:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 609 |
|
| 610 |
### Class template `basic_stringstream` <a id="stringstream">[[stringstream]]</a>
|
| 611 |
|
| 612 |
``` cpp
|
| 613 |
namespace std {
|
|
@@ -621,27 +996,52 @@ namespace std {
|
|
| 621 |
using off_type = typename traits::off_type;
|
| 622 |
using traits_type = traits;
|
| 623 |
using allocator_type = Allocator;
|
| 624 |
|
| 625 |
// [stringstream.cons], constructors
|
|
|
|
|
|
|
| 626 |
explicit basic_stringstream(
|
|
|
|
| 627 |
ios_base::openmode which = ios_base::out | ios_base::in);
|
|
|
|
| 628 |
explicit basic_stringstream(
|
| 629 |
-
|
| 630 |
ios_base::openmode which = ios_base::out | ios_base::in);
|
| 631 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 632 |
basic_stringstream(basic_stringstream&& rhs);
|
| 633 |
|
| 634 |
// [stringstream.assign], assign and swap
|
| 635 |
-
basic_stringstream& operator=(const basic_stringstream&
|
| 636 |
basic_stringstream& operator=(basic_stringstream&& rhs);
|
| 637 |
void swap(basic_stringstream& rhs);
|
| 638 |
|
| 639 |
// [stringstream.members], members
|
| 640 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 641 |
-
|
| 642 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 643 |
|
| 644 |
private:
|
| 645 |
basic_stringbuf<charT, traits> sb; // exposition only
|
| 646 |
};
|
| 647 |
|
|
@@ -658,83 +1058,156 @@ and writing from objects of class
|
|
| 658 |
associated sequence. For the sake of exposition, the maintained data is
|
| 659 |
presented here as
|
| 660 |
|
| 661 |
- `sb`, the `stringbuf` object.
|
| 662 |
|
| 663 |
-
####
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 664 |
|
| 665 |
``` cpp
|
| 666 |
explicit basic_stringstream(
|
|
|
|
| 667 |
ios_base::openmode which = ios_base::out | ios_base::in);
|
| 668 |
```
|
| 669 |
|
| 670 |
-
*Effects:*
|
| 671 |
-
`
|
| 672 |
-
`
|
| 673 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 674 |
|
| 675 |
``` cpp
|
| 676 |
explicit basic_stringstream(
|
| 677 |
-
|
| 678 |
ios_base::openmode which = ios_base::out | ios_base::in);
|
| 679 |
```
|
| 680 |
|
| 681 |
-
*Effects:*
|
| 682 |
-
`
|
| 683 |
-
`
|
| 684 |
-
`basic_stringbuf<charT, traits, Allocator>(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 685 |
|
| 686 |
``` cpp
|
| 687 |
basic_stringstream(basic_stringstream&& rhs);
|
| 688 |
```
|
| 689 |
|
| 690 |
*Effects:* Move constructs from the rvalue `rhs`. This is accomplished
|
| 691 |
by move constructing the base class, and the contained
|
| 692 |
-
`basic_stringbuf`.
|
| 693 |
-
|
|
|
|
| 694 |
|
| 695 |
-
####
|
| 696 |
-
|
| 697 |
-
``` cpp
|
| 698 |
-
basic_stringstream& operator=(basic_stringstream&& rhs);
|
| 699 |
-
```
|
| 700 |
-
|
| 701 |
-
*Effects:* Move assigns the base and members of `*this` from the base
|
| 702 |
-
and corresponding members of `rhs`.
|
| 703 |
-
|
| 704 |
-
*Returns:* `*this`.
|
| 705 |
|
| 706 |
``` cpp
|
| 707 |
void swap(basic_stringstream& rhs);
|
| 708 |
```
|
| 709 |
|
| 710 |
-
*Effects:*
|
| 711 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 712 |
|
| 713 |
``` cpp
|
| 714 |
template<class charT, class traits, class Allocator>
|
| 715 |
void swap(basic_stringstream<charT, traits, Allocator>& x,
|
| 716 |
basic_stringstream<charT, traits, Allocator>& y);
|
| 717 |
```
|
| 718 |
|
| 719 |
-
*Effects:*
|
| 720 |
|
| 721 |
#### Member functions <a id="stringstream.members">[[stringstream.members]]</a>
|
| 722 |
|
| 723 |
``` cpp
|
| 724 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 725 |
```
|
| 726 |
|
| 727 |
-
*Returns:*
|
|
|
|
| 728 |
|
| 729 |
``` cpp
|
| 730 |
-
basic_string<charT, traits, Allocator> str() const;
|
| 731 |
```
|
| 732 |
|
| 733 |
-
*
|
| 734 |
|
| 735 |
``` cpp
|
| 736 |
-
|
|
|
|
| 737 |
```
|
| 738 |
|
| 739 |
-
*Effects:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 740 |
|
|
|
|
| 50 |
using off_type = typename traits::off_type;
|
| 51 |
using traits_type = traits;
|
| 52 |
using allocator_type = Allocator;
|
| 53 |
|
| 54 |
// [stringbuf.cons], constructors
|
| 55 |
+
basic_stringbuf() : basic_stringbuf(ios_base::in | ios_base::out) {}
|
| 56 |
+
explicit basic_stringbuf(ios_base::openmode which);
|
| 57 |
explicit basic_stringbuf(
|
| 58 |
+
const basic_string<charT, traits, Allocator>& s,
|
| 59 |
ios_base::openmode which = ios_base::in | ios_base::out);
|
| 60 |
+
explicit basic_stringbuf(const Allocator& a)
|
| 61 |
+
: basic_stringbuf(ios_base::in | ios_base::out, a) {}
|
| 62 |
+
basic_stringbuf(ios_base::openmode which, const Allocator& a);
|
| 63 |
explicit basic_stringbuf(
|
| 64 |
+
basic_string<charT, traits, Allocator>&& s,
|
| 65 |
ios_base::openmode which = ios_base::in | ios_base::out);
|
| 66 |
+
template<class SAlloc>
|
| 67 |
+
basic_stringbuf(
|
| 68 |
+
const basic_string<charT, traits, SAlloc>& s, const Allocator& a)
|
| 69 |
+
: basic_stringbuf(s, ios_base::in | ios_base::out, a) {}
|
| 70 |
+
template<class SAlloc>
|
| 71 |
+
basic_stringbuf(
|
| 72 |
+
const basic_string<charT, traits, SAlloc>& s,
|
| 73 |
+
ios_base::openmode which, const Allocator& a);
|
| 74 |
+
template<class SAlloc>
|
| 75 |
+
explicit basic_stringbuf(
|
| 76 |
+
const basic_string<charT, traits, SAlloc>& s,
|
| 77 |
+
ios_base::openmode which = ios_base::in | ios_base::out);
|
| 78 |
+
basic_stringbuf(const basic_stringbuf&) = delete;
|
| 79 |
basic_stringbuf(basic_stringbuf&& rhs);
|
| 80 |
+
basic_stringbuf(basic_stringbuf&& rhs, const Allocator& a);
|
| 81 |
|
| 82 |
// [stringbuf.assign], assign and swap
|
| 83 |
+
basic_stringbuf& operator=(const basic_stringbuf&) = delete;
|
| 84 |
basic_stringbuf& operator=(basic_stringbuf&& rhs);
|
| 85 |
+
void swap(basic_stringbuf& rhs) noexcept(see below);
|
| 86 |
+
|
| 87 |
+
// [stringbuf.members], getters and setters
|
| 88 |
+
allocator_type get_allocator() const noexcept;
|
| 89 |
+
|
| 90 |
+
basic_string<charT, traits, Allocator> str() const &;
|
| 91 |
+
template<class SAlloc>
|
| 92 |
+
basic_string<charT,traits,SAlloc> str(const SAlloc& sa) const;
|
| 93 |
+
basic_string<charT, traits, Allocator> str() &&;
|
| 94 |
+
basic_string_view<charT, traits> view() const noexcept;
|
| 95 |
|
|
|
|
|
|
|
| 96 |
void str(const basic_string<charT, traits, Allocator>& s);
|
| 97 |
+
template<class SAlloc>
|
| 98 |
+
void str(const basic_string<charT, traits, SAlloc>& s);
|
| 99 |
+
void str(basic_string<charT, traits, Allocator>&& s);
|
| 100 |
|
| 101 |
protected:
|
| 102 |
// [stringbuf.virtuals], overridden virtual functions
|
| 103 |
int_type underflow() override;
|
| 104 |
int_type pbackfail(int_type c = traits::eof()) override;
|
|
|
|
| 112 |
ios_base::openmode which
|
| 113 |
= ios_base::in | ios_base::out) override;
|
| 114 |
|
| 115 |
private:
|
| 116 |
ios_base::openmode mode; // exposition only
|
| 117 |
+
basic_string<charT, traits, Allocator> buf; // exposition only
|
| 118 |
+
void init_buf_ptrs(); // exposition only
|
| 119 |
};
|
| 120 |
|
| 121 |
template<class charT, class traits, class Allocator>
|
| 122 |
void swap(basic_stringbuf<charT, traits, Allocator>& x,
|
| 123 |
+
basic_stringbuf<charT, traits, Allocator>& y) noexcept(noexcept(x.swap(y)));
|
| 124 |
}
|
| 125 |
```
|
| 126 |
|
| 127 |
The class `basic_stringbuf` is derived from `basic_streambuf` to
|
| 128 |
associate possibly the input sequence and possibly the output sequence
|
| 129 |
with a sequence of arbitrary *characters*. The sequence can be
|
| 130 |
initialized from, or made available as, an object of class
|
| 131 |
`basic_string`.
|
| 132 |
|
| 133 |
+
For the sake of exposition, the maintained data and internal pointer
|
| 134 |
+
initialization is presented here as:
|
| 135 |
|
| 136 |
- `ios_base::openmode mode`, has `in` set if the input sequence can be
|
| 137 |
read, and `out` set if the output sequence can be written.
|
| 138 |
+
- `basic_string<charT, traits, Allocator> buf` contains the underlying
|
| 139 |
+
character sequence.
|
| 140 |
+
- `init_buf_ptrs()` sets the base class’ get area [[streambuf.get.area]]
|
| 141 |
+
and put area [[streambuf.put.area]] pointers after initializing,
|
| 142 |
+
moving from, or assigning to `buf` accordingly.
|
| 143 |
|
| 144 |
+
#### Constructors <a id="stringbuf.cons">[[stringbuf.cons]]</a>
|
| 145 |
|
| 146 |
``` cpp
|
| 147 |
+
explicit basic_stringbuf(ios_base::openmode which);
|
|
|
|
| 148 |
```
|
| 149 |
|
| 150 |
+
*Effects:* Initializes the base class with `basic_streambuf()`
|
| 151 |
+
[[streambuf.cons]], and `mode` with `which`. It is
|
| 152 |
+
*implementation-defined* whether the sequence pointers (`eback()`,
|
| 153 |
+
`gptr()`, `egptr()`, `pbase()`, `pptr()`, `epptr()`) are initialized to
|
| 154 |
+
null pointers.
|
| 155 |
|
| 156 |
+
*Ensures:* `str().empty()` is `true`.
|
| 157 |
|
| 158 |
``` cpp
|
| 159 |
explicit basic_stringbuf(
|
| 160 |
const basic_string<charT, traits, Allocator>& s,
|
| 161 |
ios_base::openmode which = ios_base::in | ios_base::out);
|
| 162 |
```
|
| 163 |
|
| 164 |
+
*Effects:* Initializes the base class with `basic_streambuf()`
|
| 165 |
+
[[streambuf.cons]], `mode` with `which`, and `buf` with `s`, then calls
|
| 166 |
+
`init_buf_ptrs()`.
|
| 167 |
+
|
| 168 |
+
``` cpp
|
| 169 |
+
basic_stringbuf(ios_base::openmode which, const Allocator &a);
|
| 170 |
+
```
|
| 171 |
+
|
| 172 |
+
*Effects:* Initializes the base class with `basic_streambuf()`
|
| 173 |
+
[[streambuf.cons]], `mode` with `which`, and `buf` with `a`, then calls
|
| 174 |
+
`init_buf_ptrs()`.
|
| 175 |
+
|
| 176 |
+
*Ensures:* `str().empty()` is `true`.
|
| 177 |
+
|
| 178 |
+
``` cpp
|
| 179 |
+
explicit basic_stringbuf(
|
| 180 |
+
basic_string<charT, traits, Allocator>&& s,
|
| 181 |
+
ios_base::openmode which = ios_base::in | ios_base::out);
|
| 182 |
+
```
|
| 183 |
+
|
| 184 |
+
*Effects:* Initializes the base class with `basic_streambuf()`
|
| 185 |
+
[[streambuf.cons]], `mode` with `which`, and `buf` with `std::move(s)`,
|
| 186 |
+
then calls `init_buf_ptrs()`.
|
| 187 |
+
|
| 188 |
+
``` cpp
|
| 189 |
+
template<class SAlloc>
|
| 190 |
+
basic_stringbuf(
|
| 191 |
+
const basic_string<charT, traits, SAlloc>& s,
|
| 192 |
+
ios_base::openmode which, const Allocator &a);
|
| 193 |
+
```
|
| 194 |
+
|
| 195 |
+
*Effects:* Initializes the base class with `basic_streambuf()`
|
| 196 |
+
[[streambuf.cons]], `mode` with `which`, and `buf` with `{s,a}`, then
|
| 197 |
+
calls `init_buf_ptrs()`.
|
| 198 |
+
|
| 199 |
+
``` cpp
|
| 200 |
+
template<class SAlloc>
|
| 201 |
+
explicit basic_stringbuf(
|
| 202 |
+
const basic_string<charT, traits, SAlloc>& s,
|
| 203 |
+
ios_base::openmode which = ios_base::in | ios_base::out);
|
| 204 |
+
```
|
| 205 |
+
|
| 206 |
+
*Constraints:* `is_same_v<SAlloc,Allocator>` is `false`.
|
| 207 |
+
|
| 208 |
+
*Effects:* Initializes the base class with `basic_streambuf()`
|
| 209 |
+
[[streambuf.cons]], `mode` with `which`, and `buf` with `s`, then calls
|
| 210 |
+
`init_buf_ptrs()`.
|
| 211 |
|
| 212 |
``` cpp
|
| 213 |
basic_stringbuf(basic_stringbuf&& rhs);
|
| 214 |
+
basic_stringbuf(basic_stringbuf&& rhs, const Allocator& a);
|
| 215 |
```
|
| 216 |
|
| 217 |
+
*Effects:* Copy constructs the base class from `rhs` and initializes
|
| 218 |
+
`mode` with `rhs.mode`. In the first form `buf` is initialized from
|
| 219 |
+
`std::move(rhs).str()`. In the second form `buf` is initialized from
|
| 220 |
+
`{std::move(rhs).str(), a}`. It is *implementation-defined* whether the
|
| 221 |
+
sequence pointers in `*this` (`eback()`, `gptr()`, `egptr()`, `pbase()`,
|
| 222 |
+
`pptr()`, `epptr()`) obtain the values which `rhs` had.
|
| 223 |
|
| 224 |
+
*Ensures:* Let `rhs_p` refer to the state of `rhs` just prior to this
|
| 225 |
+
construction and let `rhs_a` refer to the state of `rhs` just after this
|
| 226 |
+
construction.
|
| 227 |
|
| 228 |
- `str() == rhs_p.str()`
|
| 229 |
- `gptr() - eback() == rhs_p.gptr() - rhs_p.eback()`
|
| 230 |
- `egptr() - eback() == rhs_p.egptr() - rhs_p.eback()`
|
| 231 |
- `pptr() - pbase() == rhs_p.pptr() - rhs_p.pbase()`
|
|
|
|
| 234 |
- `if (gptr()) gptr() != rhs_a.gptr()`
|
| 235 |
- `if (egptr()) egptr() != rhs_a.egptr()`
|
| 236 |
- `if (pbase()) pbase() != rhs_a.pbase()`
|
| 237 |
- `if (pptr()) pptr() != rhs_a.pptr()`
|
| 238 |
- `if (epptr()) epptr() != rhs_a.epptr()`
|
| 239 |
+
- `getloc() == rhs_p.getloc()`
|
| 240 |
+
- `rhs` is empty but usable, as if `std::move(rhs).str()` was called.
|
| 241 |
|
| 242 |
+
#### Assignment and swap <a id="stringbuf.assign">[[stringbuf.assign]]</a>
|
| 243 |
|
| 244 |
``` cpp
|
| 245 |
basic_stringbuf& operator=(basic_stringbuf&& rhs);
|
| 246 |
```
|
| 247 |
|
|
|
|
| 250 |
(see [[stringbuf.cons]]).
|
| 251 |
|
| 252 |
*Returns:* `*this`.
|
| 253 |
|
| 254 |
``` cpp
|
| 255 |
+
void swap(basic_stringbuf& rhs) noexcept(see below);
|
| 256 |
```
|
| 257 |
|
| 258 |
+
*Preconditions:*
|
| 259 |
+
`allocator_traits<Allocator>::propagate_on_container_swap::value` is
|
| 260 |
+
`true` or `get_allocator() == s.get_allocator()` is `true`.
|
| 261 |
+
|
| 262 |
*Effects:* Exchanges the state of `*this` and `rhs`.
|
| 263 |
|
| 264 |
+
*Remarks:* The expression inside `noexcept` is equivalent to:
|
| 265 |
+
`allocator_traits<Allocator>::propagate_on_container_swap::value ||`
|
| 266 |
+
`allocator_traits<Allocator>::is_always_equal::value`.
|
| 267 |
+
|
| 268 |
``` cpp
|
| 269 |
template<class charT, class traits, class Allocator>
|
| 270 |
void swap(basic_stringbuf<charT, traits, Allocator>& x,
|
| 271 |
+
basic_stringbuf<charT, traits, Allocator>& y) noexcept(noexcept(x.swap(y)));
|
| 272 |
```
|
| 273 |
|
| 274 |
+
*Effects:* Equivalent to: `x.swap(y)`.
|
| 275 |
|
| 276 |
#### Member functions <a id="stringbuf.members">[[stringbuf.members]]</a>
|
| 277 |
|
| 278 |
+
The member functions getting the underlying character sequence all refer
|
| 279 |
+
to a `high_mark` value, where `high_mark` represents the position one
|
| 280 |
+
past the highest initialized character in the buffer. Characters can be
|
| 281 |
+
initialized by writing to the stream, by constructing the
|
| 282 |
+
`basic_stringbuf` passing a `basic_string` argument, or by calling one
|
| 283 |
+
of the `str` member functions passing a `basic_string` as an argument.
|
| 284 |
+
In the latter case, all characters initialized prior to the call are now
|
| 285 |
+
considered uninitialized (except for those characters re-initialized by
|
| 286 |
+
the new `basic_string`).
|
| 287 |
+
|
| 288 |
+
``` cpp
|
| 289 |
+
void init_buf_ptrs(); // exposition only
|
| 290 |
+
```
|
| 291 |
+
|
| 292 |
+
*Effects:* Initializes the input and output sequences from `buf`
|
| 293 |
+
according to `mode`.
|
| 294 |
+
|
| 295 |
+
*Ensures:*
|
| 296 |
+
|
| 297 |
+
- If `ios_base::out` is set in `mode`, `pbase()` points to `buf.front()`
|
| 298 |
+
and `epptr() >= pbase() + buf.size()` is `true`;
|
| 299 |
+
- in addition, if `ios_base::ate` is set in `mode`,
|
| 300 |
+
`pptr() == pbase() + buf.size()` is `true`,
|
| 301 |
+
- otherwise `pptr() == pbase()` is `true`.
|
| 302 |
+
- If `ios_base::in` is set in `mode`, `eback()` points to `buf.front()`,
|
| 303 |
+
and `(gptr() == eback() && egptr() == eback() + buf.size())` is
|
| 304 |
+
`true`.
|
| 305 |
+
|
| 306 |
+
[*Note 1*: For efficiency reasons, stream buffer operations might
|
| 307 |
+
violate invariants of `buf` while it is held encapsulated in the
|
| 308 |
+
`basic_stringbuf`, e.g., by writing to characters in the range
|
| 309 |
+
\[`buf.data() + buf.size()`, `buf.data() + buf.capacity()`). All
|
| 310 |
+
operations retrieving a `basic_string` from `buf` ensure that the
|
| 311 |
+
`basic_string` invariants hold on the returned value. — *end note*]
|
| 312 |
+
|
| 313 |
+
``` cpp
|
| 314 |
+
allocator_type get_allocator() const noexcept;
|
| 315 |
+
```
|
| 316 |
+
|
| 317 |
+
*Returns:* `buf.get_allocator()`.
|
| 318 |
+
|
| 319 |
+
``` cpp
|
| 320 |
+
basic_string<charT, traits, Allocator> str() const &;
|
| 321 |
+
```
|
| 322 |
+
|
| 323 |
+
*Effects:* Equivalent to:
|
| 324 |
+
|
| 325 |
+
``` cpp
|
| 326 |
+
return basic_string<charT, traits, Allocator>(view(), get_allocator());
|
| 327 |
+
```
|
| 328 |
+
|
| 329 |
``` cpp
|
| 330 |
+
template<class SAlloc>
|
| 331 |
+
basic_string<charT, traits, SAlloc> str(const SAlloc& sa) const;
|
| 332 |
+
```
|
| 333 |
+
|
| 334 |
+
*Constraints:* `SAlloc` is a type that qualifies as an
|
| 335 |
+
allocator [[container.requirements.general]].
|
| 336 |
+
|
| 337 |
+
*Effects:* Equivalent to:
|
| 338 |
+
|
| 339 |
+
``` cpp
|
| 340 |
+
return basic_string<charT, traits, SAlloc>(view(), sa);
|
| 341 |
+
```
|
| 342 |
+
|
| 343 |
+
``` cpp
|
| 344 |
+
basic_string<charT, traits, Allocator> str() &&;
|
| 345 |
+
```
|
| 346 |
+
|
| 347 |
+
*Returns:* A `basic_string<charT, traits, Allocator>` object move
|
| 348 |
+
constructed from the `basic_stringbuf`’s underlying character sequence
|
| 349 |
+
in `buf`. This can be achieved by first adjusting `buf` to have the same
|
| 350 |
+
content as `view()`.
|
| 351 |
+
|
| 352 |
+
*Ensures:* The underlying character sequence `buf` is empty and
|
| 353 |
+
`pbase()`, `pptr()`, `epptr()`, `eback()`, `gptr()`, and `egptr()` are
|
| 354 |
+
initialized as if by calling `init_buf_ptrs()` with an empty `buf`.
|
| 355 |
+
|
| 356 |
+
``` cpp
|
| 357 |
+
basic_string_view<charT, traits> view() const noexcept;
|
| 358 |
+
```
|
| 359 |
+
|
| 360 |
+
Let `sv` be `basic_string_view<charT, traits>`.
|
| 361 |
+
|
| 362 |
+
*Returns:* A `sv` object referring to the `basic_stringbuf`’s underlying
|
| 363 |
+
character sequence in `buf`:
|
| 364 |
+
|
| 365 |
+
- If `ios_base::out` is set in `mode`, then
|
| 366 |
+
`sv(pbase(), high_mark-pbase())` is returned.
|
| 367 |
+
- Otherwise, if `ios_base::in` is set in `mode`, then
|
| 368 |
+
`sv(eback(), egptr()-eback())` is returned.
|
| 369 |
+
- Otherwise, `sv()` is returned.
|
| 370 |
+
|
| 371 |
+
[*Note 2*: Using the returned `sv` object after destruction or
|
| 372 |
+
invalidation of the character sequence underlying `*this` is undefined
|
| 373 |
+
behavior, unless `sv.empty()` is `true`. — *end note*]
|
| 374 |
|
| 375 |
``` cpp
|
| 376 |
void str(const basic_string<charT, traits, Allocator>& s);
|
| 377 |
```
|
| 378 |
|
| 379 |
+
*Effects:* Equivalent to:
|
| 380 |
+
|
| 381 |
+
``` cpp
|
| 382 |
+
buf = s;
|
| 383 |
+
init_buf_ptrs();
|
| 384 |
+
```
|
| 385 |
+
|
| 386 |
+
``` cpp
|
| 387 |
+
template<class SAlloc>
|
| 388 |
+
void str(const basic_string<charT, traits, SAlloc>& s);
|
| 389 |
+
```
|
| 390 |
+
|
| 391 |
+
*Constraints:* `is_same_v<SAlloc,Allocator>` is `false`.
|
| 392 |
+
|
| 393 |
+
*Effects:* Equivalent to:
|
| 394 |
+
|
| 395 |
+
``` cpp
|
| 396 |
+
buf = s;
|
| 397 |
+
init_buf_ptrs();
|
| 398 |
+
```
|
| 399 |
+
|
| 400 |
+
``` cpp
|
| 401 |
+
void str(basic_string<charT, traits, Allocator>&& s);
|
| 402 |
+
```
|
| 403 |
+
|
| 404 |
+
*Effects:* Equivalent to:
|
| 405 |
+
|
| 406 |
+
``` cpp
|
| 407 |
+
buf = std::move(s);
|
| 408 |
+
init_buf_ptrs();
|
| 409 |
+
```
|
| 410 |
|
| 411 |
#### Overridden virtual functions <a id="stringbuf.virtuals">[[stringbuf.virtuals]]</a>
|
| 412 |
|
| 413 |
``` cpp
|
| 414 |
int_type underflow() override;
|
|
|
|
| 435 |
`ios_base::out` is nonzero, assigns `c` to `*``gptr()`. Returns: `c`.
|
| 436 |
- If `traits::eq_int_type(c, traits::eof())` returns `true` and if the
|
| 437 |
input sequence has a putback position available, assigns `gptr() - 1`
|
| 438 |
to `gptr()`. Returns: `traits::not_eof(c)`.
|
| 439 |
|
| 440 |
+
*Returns:* As specified above, or `traits::eof()` to indicate failure.
|
| 441 |
|
| 442 |
*Remarks:* If the function can succeed in more than one of these ways,
|
| 443 |
it is unspecified which way is chosen.
|
| 444 |
|
| 445 |
``` cpp
|
|
|
|
| 458 |
`traits::eof()`.
|
| 459 |
|
| 460 |
*Remarks:* The function can alter the number of write positions
|
| 461 |
available as a result of any call.
|
| 462 |
|
| 463 |
+
*Returns:* As specified above, or `traits::eof()` to indicate failure.
|
| 464 |
|
| 465 |
+
The function can make a write position available only if `ios_base::out`
|
| 466 |
+
is set in `mode`. To make a write position available, the function
|
| 467 |
+
reallocates (or initially allocates) an array object with a sufficient
|
| 468 |
+
number of elements to hold the current array object (if any), plus at
|
| 469 |
+
least one additional write position. If `ios_base::in` is set in `mode`,
|
| 470 |
+
the function alters the read end pointer `egptr()` to point just past
|
| 471 |
+
the new write position.
|
| 472 |
|
| 473 |
``` cpp
|
| 474 |
pos_type seekoff(off_type off, ios_base::seekdir way,
|
| 475 |
ios_base::openmode which
|
| 476 |
= ios_base::in | ios_base::out) override;
|
| 477 |
```
|
| 478 |
|
| 479 |
*Effects:* Alters the stream position within one of the controlled
|
| 480 |
+
sequences, if possible, as indicated in [[stringbuf.seekoff.pos]].
|
|
|
|
| 481 |
|
| 482 |
+
**Table: `seekoff` positioning** <a id="stringbuf.seekoff.pos">[stringbuf.seekoff.pos]</a>
|
| 483 |
|
| 484 |
| Conditions | Result |
|
| 485 |
+
| ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------- |
|
| 486 |
+
| `ios_base::in` is set in `which` | positions the input sequence |
|
| 487 |
+
| `ios_base::out` is set in `which` | positions the output sequence |
|
| 488 |
+
| both `ios_base::in` and `ios_base::out` are set in `which` and either<br> `way == ios_base::beg` or<br> `way == ios_base::end` | positions both the input and the output sequences |
|
| 489 |
| Otherwise | the positioning operation fails. |
|
| 490 |
|
| 491 |
|
| 492 |
+
For a sequence to be positioned, the function determines `newoff` as
|
| 493 |
+
indicated in [[stringbuf.seekoff.newoff]]. If the sequence’s next
|
| 494 |
+
pointer (either `gptr()` or `pptr()`) is a null pointer and `newoff` is
|
| 495 |
+
nonzero, the positioning operation fails.
|
| 496 |
|
| 497 |
+
**Table: `newoff` values** <a id="stringbuf.seekoff.newoff">[stringbuf.seekoff.newoff]</a>
|
| 498 |
|
| 499 |
| Condition | `newoff` Value |
|
| 500 |
| ---------------------- | ----------------------------------------------------------------------- |
|
| 501 |
| `way == ios_base::beg` | 0 |
|
| 502 |
| `way == ios_base::cur` | the next pointer minus the beginning pointer (`xnext - xbeg`). |
|
| 503 |
| `way == ios_base::end` | the high mark pointer minus the beginning pointer (`high_mark - xbeg`). |
|
| 504 |
|
| 505 |
|
| 506 |
If `(newoff + off) < 0`, or if `newoff + off` refers to an uninitialized
|
| 507 |
+
character [[stringbuf.members]], the positioning operation fails.
|
| 508 |
Otherwise, the function assigns `xbeg + newoff + off` to the next
|
| 509 |
pointer `xnext`.
|
| 510 |
|
| 511 |
*Returns:* `pos_type(newoff)`, constructed from the resultant offset
|
| 512 |
`newoff` (of type `off_type`), that stores the resultant stream
|
|
|
|
| 548 |
using off_type = typename traits::off_type;
|
| 549 |
using traits_type = traits;
|
| 550 |
using allocator_type = Allocator;
|
| 551 |
|
| 552 |
// [istringstream.cons], constructors
|
| 553 |
+
basic_istringstream() : basic_istringstream(ios_base::in) {}
|
| 554 |
+
explicit basic_istringstream(ios_base::openmode which);
|
| 555 |
explicit basic_istringstream(
|
| 556 |
+
const basic_string<charT, traits, Allocator>& s,
|
| 557 |
ios_base::openmode which = ios_base::in);
|
| 558 |
+
basic_istringstream(ios_base::openmode which, const Allocator& a);
|
| 559 |
explicit basic_istringstream(
|
| 560 |
+
basic_string<charT, traits, Allocator>&& s,
|
| 561 |
ios_base::openmode which = ios_base::in);
|
| 562 |
+
template<class SAlloc>
|
| 563 |
+
basic_istringstream(
|
| 564 |
+
const basic_string<charT, traits, SAlloc>& s, const Allocator& a)
|
| 565 |
+
: basic_istringstream(s, ios_base::in, a) {}
|
| 566 |
+
template<class SAlloc>
|
| 567 |
+
basic_istringstream(
|
| 568 |
+
const basic_string<charT, traits, SAlloc>& s,
|
| 569 |
+
ios_base::openmode which, const Allocator& a);
|
| 570 |
+
template<class SAlloc>
|
| 571 |
+
explicit basic_istringstream(
|
| 572 |
+
const basic_string<charT, traits, SAlloc>& s,
|
| 573 |
+
ios_base::openmode which = ios_base::in);
|
| 574 |
+
basic_istringstream(const basic_istringstream&) = delete;
|
| 575 |
basic_istringstream(basic_istringstream&& rhs);
|
| 576 |
|
| 577 |
// [istringstream.assign], assign and swap
|
| 578 |
+
basic_istringstream& operator=(const basic_istringstream&) = delete;
|
| 579 |
basic_istringstream& operator=(basic_istringstream&& rhs);
|
| 580 |
void swap(basic_istringstream& rhs);
|
| 581 |
|
| 582 |
// [istringstream.members], members
|
| 583 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 584 |
+
basic_string<charT, traits, Allocator> str() const &;
|
| 585 |
+
template<class SAlloc>
|
| 586 |
+
basic_string<charT,traits,SAlloc> str(const SAlloc& sa) const;
|
| 587 |
+
basic_string<charT, traits, Allocator> str() &&;
|
| 588 |
+
basic_string_view<charT, traits> view() const noexcept;
|
| 589 |
|
|
|
|
| 590 |
void str(const basic_string<charT, traits, Allocator>& s);
|
| 591 |
+
template<class SAlloc>
|
| 592 |
+
void str(const basic_string<charT, traits, SAlloc>& s);
|
| 593 |
+
void str(basic_string<charT, traits, Allocator>&& s);
|
| 594 |
+
|
| 595 |
private:
|
| 596 |
basic_stringbuf<charT, traits, Allocator> sb; // exposition only
|
| 597 |
};
|
| 598 |
|
| 599 |
template<class charT, class traits, class Allocator>
|
|
|
|
| 608 |
associated storage. For the sake of exposition, the maintained data is
|
| 609 |
presented here as:
|
| 610 |
|
| 611 |
- `sb`, the `stringbuf` object.
|
| 612 |
|
| 613 |
+
#### Constructors <a id="istringstream.cons">[[istringstream.cons]]</a>
|
| 614 |
|
| 615 |
``` cpp
|
| 616 |
+
explicit basic_istringstream(ios_base::openmode which);
|
| 617 |
```
|
| 618 |
|
| 619 |
+
*Effects:* Initializes the base class with
|
| 620 |
+
`basic_istream<charT, traits>(addressof(sb))` [[istream]] and `sb` with
|
| 621 |
+
`basic_stringbuf<charT, traits, Allocator>(which | ios_base::in)`
|
| 622 |
+
[[stringbuf.cons]].
|
| 623 |
|
| 624 |
``` cpp
|
| 625 |
explicit basic_istringstream(
|
| 626 |
+
const basic_string<charT, traits, Allocator>& s,
|
| 627 |
ios_base::openmode which = ios_base::in);
|
| 628 |
```
|
| 629 |
|
| 630 |
+
*Effects:* Initializes the base class with
|
| 631 |
+
`basic_istream<charT, traits>(addressof(sb))` [[istream]] and `sb` with
|
| 632 |
+
`basic_stringbuf<charT, traits, Allocator>(s, which | ios_base::in)`([[stringbuf.cons]]).
|
| 633 |
+
|
| 634 |
+
``` cpp
|
| 635 |
+
basic_istringstream(ios_base::openmode which, const Allocator& a);
|
| 636 |
+
```
|
| 637 |
+
|
| 638 |
+
*Effects:* Initializes the base class with
|
| 639 |
+
`basic_istream<charT, traits>(addressof(sb))` [[istream]] and `sb` with
|
| 640 |
+
`basic_stringbuf<charT, traits, Allocator>(which | ios_base::in, a)`
|
| 641 |
+
[[stringbuf.cons]].
|
| 642 |
+
|
| 643 |
+
``` cpp
|
| 644 |
+
explicit basic_istringstream(
|
| 645 |
+
basic_string<charT, traits, Allocator>&& s,
|
| 646 |
+
ios_base::openmode which = ios_base::in);
|
| 647 |
+
```
|
| 648 |
+
|
| 649 |
+
*Effects:* Initializes the base class with
|
| 650 |
+
`basic_istream<charT, traits>(addressof(sb))` [[istream]] and `sb` with
|
| 651 |
+
`basic_stringbuf<charT, traits, Allocator>(std::move(s), which | ios_base::in)`
|
| 652 |
+
[[stringbuf.cons]].
|
| 653 |
+
|
| 654 |
+
``` cpp
|
| 655 |
+
template<class SAlloc>
|
| 656 |
+
basic_istringstream(
|
| 657 |
+
const basic_string<charT, traits, SAlloc>& s,
|
| 658 |
+
ios_base::openmode which, const Allocator& a);
|
| 659 |
+
```
|
| 660 |
+
|
| 661 |
+
*Effects:* Initializes the base class with
|
| 662 |
+
`basic_istream<charT, traits>(addressof(sb))` [[istream]] and `sb` with
|
| 663 |
+
`basic_stringbuf<charT, traits, Allocator>(s, which | ios_base::in, a)`([[stringbuf.cons]]).
|
| 664 |
+
|
| 665 |
+
``` cpp
|
| 666 |
+
template<class SAlloc>
|
| 667 |
+
explicit basic_istringstream(
|
| 668 |
+
const basic_string<charT, traits, SAlloc>& s,
|
| 669 |
+
ios_base::openmode which = ios_base::in);
|
| 670 |
+
```
|
| 671 |
+
|
| 672 |
+
*Effects:* Initializes the base class with
|
| 673 |
+
`basic_istream<charT, traits>(addressof(sb))` [[istream]] and `sb` with
|
| 674 |
+
`basic_stringbuf<charT, traits, Allocator>(s, which | ios_base::in)`
|
| 675 |
+
[[stringbuf.cons]].
|
| 676 |
|
| 677 |
``` cpp
|
| 678 |
basic_istringstream(basic_istringstream&& rhs);
|
| 679 |
```
|
| 680 |
|
| 681 |
*Effects:* Move constructs from the rvalue `rhs`. This is accomplished
|
| 682 |
by move constructing the base class, and the contained
|
| 683 |
+
`basic_stringbuf`. Then calls
|
| 684 |
+
`basic_istream<charT, traits>::set_rdbuf(addressof(sb))` to install the
|
| 685 |
+
contained `basic_stringbuf`.
|
| 686 |
|
| 687 |
+
#### Assignment and swap <a id="istringstream.assign">[[istringstream.assign]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 688 |
|
| 689 |
``` cpp
|
| 690 |
void swap(basic_istringstream& rhs);
|
| 691 |
```
|
| 692 |
|
| 693 |
+
*Effects:* Equivalent to:
|
| 694 |
+
|
| 695 |
+
``` cpp
|
| 696 |
+
basic_istream<charT, traits>::swap(rhs);
|
| 697 |
+
sb.swap(rhs.sb);
|
| 698 |
+
```
|
| 699 |
|
| 700 |
``` cpp
|
| 701 |
template<class charT, class traits, class Allocator>
|
| 702 |
void swap(basic_istringstream<charT, traits, Allocator>& x,
|
| 703 |
basic_istringstream<charT, traits, Allocator>& y);
|
| 704 |
```
|
| 705 |
|
| 706 |
+
*Effects:* Equivalent to: `x.swap(y)`.
|
| 707 |
|
| 708 |
#### Member functions <a id="istringstream.members">[[istringstream.members]]</a>
|
| 709 |
|
| 710 |
``` cpp
|
| 711 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 712 |
```
|
| 713 |
|
| 714 |
*Returns:*
|
| 715 |
+
`const_cast<basic_stringbuf<charT, traits, Allocator>*>(addressof(sb))`.
|
| 716 |
|
| 717 |
``` cpp
|
| 718 |
+
basic_string<charT, traits, Allocator> str() const &;
|
| 719 |
```
|
| 720 |
|
| 721 |
+
*Effects:* Equivalent to: `return rdbuf()->str();`
|
| 722 |
+
|
| 723 |
+
``` cpp
|
| 724 |
+
template<class SAlloc>
|
| 725 |
+
basic_string<charT,traits,SAlloc> str(const SAlloc& sa) const;
|
| 726 |
+
```
|
| 727 |
+
|
| 728 |
+
*Effects:* Equivalent to: `return rdbuf()->str(sa);`
|
| 729 |
+
|
| 730 |
+
``` cpp
|
| 731 |
+
basic_string<charT,traits,Allocator> str() &&;
|
| 732 |
+
```
|
| 733 |
+
|
| 734 |
+
*Effects:* Equivalent to: `return std::move(*rdbuf()).str();`
|
| 735 |
+
|
| 736 |
+
``` cpp
|
| 737 |
+
basic_string_view<charT, traits> view() const noexcept;
|
| 738 |
+
```
|
| 739 |
+
|
| 740 |
+
*Effects:* Equivalent to: `return rdbuf()->view();`
|
| 741 |
|
| 742 |
``` cpp
|
| 743 |
void str(const basic_string<charT, traits, Allocator>& s);
|
| 744 |
```
|
| 745 |
|
| 746 |
+
*Effects:* Equivalent to: `rdbuf()->str(s);`
|
| 747 |
+
|
| 748 |
+
``` cpp
|
| 749 |
+
template<class SAlloc>
|
| 750 |
+
void str(const basic_string<charT, traits, SAlloc>& s);
|
| 751 |
+
```
|
| 752 |
+
|
| 753 |
+
*Effects:* Equivalent to: `rdbuf()->str(s);`
|
| 754 |
+
|
| 755 |
+
``` cpp
|
| 756 |
+
void str(basic_string<charT, traits, Allocator>&& s);
|
| 757 |
+
```
|
| 758 |
+
|
| 759 |
+
*Effects:* Equivalent to: `rdbuf()->str(std::move(s));`
|
| 760 |
|
| 761 |
### Class template `basic_ostringstream` <a id="ostringstream">[[ostringstream]]</a>
|
| 762 |
|
| 763 |
``` cpp
|
| 764 |
namespace std {
|
|
|
|
| 772 |
using off_type = typename traits::off_type;
|
| 773 |
using traits_type = traits;
|
| 774 |
using allocator_type = Allocator;
|
| 775 |
|
| 776 |
// [ostringstream.cons], constructors
|
| 777 |
+
basic_ostringstream() : basic_ostringstream(ios_base::out) {}
|
| 778 |
+
explicit basic_ostringstream(ios_base::openmode which);
|
| 779 |
explicit basic_ostringstream(
|
| 780 |
+
const basic_string<charT, traits, Allocator>& s,
|
| 781 |
ios_base::openmode which = ios_base::out);
|
| 782 |
+
basic_ostringstream(ios_base::openmode which, const Allocator& a);
|
| 783 |
explicit basic_ostringstream(
|
| 784 |
+
basic_string<charT, traits, Allocator>&& s,
|
| 785 |
ios_base::openmode which = ios_base::out);
|
| 786 |
+
template<class SAlloc>
|
| 787 |
+
basic_ostringstream(
|
| 788 |
+
const basic_string<charT, traits, SAlloc>& s, const Allocator& a)
|
| 789 |
+
: basic_ostringstream(s, ios_base::out, a) {}
|
| 790 |
+
template<class SAlloc>
|
| 791 |
+
basic_ostringstream(
|
| 792 |
+
const basic_string<charT, traits, SAlloc>& s,
|
| 793 |
+
ios_base::openmode which, const Allocator& a);
|
| 794 |
+
template<class SAlloc>
|
| 795 |
+
explicit basic_ostringstream(
|
| 796 |
+
const basic_string<charT, traits, SAlloc>& s,
|
| 797 |
+
ios_base::openmode which = ios_base::out);
|
| 798 |
+
basic_ostringstream(const basic_ostringstream&) = delete;
|
| 799 |
basic_ostringstream(basic_ostringstream&& rhs);
|
| 800 |
|
| 801 |
// [ostringstream.assign], assign and swap
|
| 802 |
+
basic_ostringstream& operator=(const basic_ostringstream&) = delete;
|
| 803 |
basic_ostringstream& operator=(basic_ostringstream&& rhs);
|
| 804 |
void swap(basic_ostringstream& rhs);
|
| 805 |
|
| 806 |
// [ostringstream.members], members
|
| 807 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 808 |
|
| 809 |
+
basic_string<charT, traits, Allocator> str() const &;
|
| 810 |
+
template<class SAlloc>
|
| 811 |
+
basic_string<charT,traits,SAlloc> str(const SAlloc& sa) const;
|
| 812 |
+
basic_string<charT, traits, Allocator> str() &&;
|
| 813 |
+
basic_string_view<charT, traits> view() const noexcept;
|
| 814 |
+
|
| 815 |
void str(const basic_string<charT, traits, Allocator>& s);
|
| 816 |
+
template<class SAlloc>
|
| 817 |
+
void str(const basic_string<charT, traits, SAlloc>& s);
|
| 818 |
+
void str(basic_string<charT, traits, Allocator>&& s);
|
| 819 |
+
|
| 820 |
private:
|
| 821 |
basic_stringbuf<charT, traits, Allocator> sb; // exposition only
|
| 822 |
};
|
| 823 |
|
| 824 |
template<class charT, class traits, class Allocator>
|
|
|
|
| 832 |
uses a `basic_stringbuf` object to control the associated storage. For
|
| 833 |
the sake of exposition, the maintained data is presented here as:
|
| 834 |
|
| 835 |
- `sb`, the `stringbuf` object.
|
| 836 |
|
| 837 |
+
#### Constructors <a id="ostringstream.cons">[[ostringstream.cons]]</a>
|
| 838 |
+
|
| 839 |
+
``` cpp
|
| 840 |
+
explicit basic_ostringstream(ios_base::openmode which);
|
| 841 |
+
```
|
| 842 |
+
|
| 843 |
+
*Effects:* Initializes the base class with
|
| 844 |
+
`basic_ostream<charT, traits>(addressof(sb))` [[ostream]] and `sb` with
|
| 845 |
+
`basic_stringbuf<charT, traits, Allocator>(which | ios_base::out)`
|
| 846 |
+
[[stringbuf.cons]].
|
| 847 |
|
| 848 |
``` cpp
|
| 849 |
explicit basic_ostringstream(
|
| 850 |
+
const basic_string<charT, traits, Allocator>& s,
|
| 851 |
ios_base::openmode which = ios_base::out);
|
| 852 |
```
|
| 853 |
|
| 854 |
+
*Effects:* Initializes the base class with
|
| 855 |
+
`basic_ostream<charT, traits>(addressof(sb))` [[ostream]] and `sb` with
|
| 856 |
+
`basic_stringbuf<charT, traits, Allocator>(s, which | ios_base::out)`([[stringbuf.cons]]).
|
| 857 |
+
|
| 858 |
+
``` cpp
|
| 859 |
+
basic_ostringstream(ios_base::openmode which, const Allocator& a);
|
| 860 |
+
```
|
| 861 |
+
|
| 862 |
+
*Effects:* Initializes the base class with
|
| 863 |
+
`basic_ostream<charT, traits>(addressof(sb))` [[ostream]] and `sb` with
|
| 864 |
+
`basic_stringbuf<charT, traits, Allocator>(which | ios_base::out, a)`([[stringbuf.cons]]).
|
| 865 |
|
| 866 |
``` cpp
|
| 867 |
explicit basic_ostringstream(
|
| 868 |
+
basic_string<charT, traits, Allocator>&& s,
|
| 869 |
ios_base::openmode which = ios_base::out);
|
| 870 |
```
|
| 871 |
|
| 872 |
+
*Effects:* Initializes the base class with
|
| 873 |
+
`basic_ostream<charT, traits>(addressof(sb))` [[ostream]] and `sb` with
|
| 874 |
+
`basic_stringbuf<charT, traits, Allocator>(std::move(s), which | ios_base::out)`
|
| 875 |
+
[[stringbuf.cons]].
|
| 876 |
+
|
| 877 |
+
``` cpp
|
| 878 |
+
template<class SAlloc>
|
| 879 |
+
basic_ostringstream(
|
| 880 |
+
const basic_string<charT, traits, SAlloc>& s,
|
| 881 |
+
ios_base::openmode which, const Allocator& a);
|
| 882 |
+
```
|
| 883 |
+
|
| 884 |
+
*Effects:* Initializes the base class with
|
| 885 |
+
`basic_ostream<charT, traits>(addressof(sb))` [[ostream]] and `sb` with
|
| 886 |
+
`basic_stringbuf<charT, traits, Allocator>(s, which | ios_base::out, a)`([[stringbuf.cons]]).
|
| 887 |
+
|
| 888 |
+
``` cpp
|
| 889 |
+
template<class SAlloc>
|
| 890 |
+
explicit basic_ostringstream(
|
| 891 |
+
const basic_string<charT, traits, SAlloc>& s,
|
| 892 |
+
ios_base::openmode which = ios_base::out);
|
| 893 |
+
```
|
| 894 |
+
|
| 895 |
+
*Constraints:* `is_same_v<SAlloc,Allocator>` is `false`.
|
| 896 |
+
|
| 897 |
+
*Effects:* Initializes the base class with
|
| 898 |
+
`basic_ostream<charT, traits>(addressof(sb))` [[ostream]] and `sb` with
|
| 899 |
+
`basic_stringbuf<charT, traits, Allocator>(s, which | ios_base::out)`([[stringbuf.cons]]).
|
| 900 |
|
| 901 |
``` cpp
|
| 902 |
basic_ostringstream(basic_ostringstream&& rhs);
|
| 903 |
```
|
| 904 |
|
| 905 |
*Effects:* Move constructs from the rvalue `rhs`. This is accomplished
|
| 906 |
by move constructing the base class, and the contained
|
| 907 |
+
`basic_stringbuf`. Then calls
|
| 908 |
+
`basic_ostream<charT, traits>::set_rdbuf(addressof(sb))` to install the
|
| 909 |
+
contained `basic_stringbuf`.
|
| 910 |
|
| 911 |
+
#### Assignment and swap <a id="ostringstream.assign">[[ostringstream.assign]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 912 |
|
| 913 |
``` cpp
|
| 914 |
void swap(basic_ostringstream& rhs);
|
| 915 |
```
|
| 916 |
|
| 917 |
+
*Effects:* Equivalent to:
|
| 918 |
+
|
| 919 |
+
``` cpp
|
| 920 |
+
basic_ostream<charT, traits>::swap(rhs);
|
| 921 |
+
sb.swap(rhs.sb);
|
| 922 |
+
```
|
| 923 |
|
| 924 |
``` cpp
|
| 925 |
template<class charT, class traits, class Allocator>
|
| 926 |
void swap(basic_ostringstream<charT, traits, Allocator>& x,
|
| 927 |
basic_ostringstream<charT, traits, Allocator>& y);
|
| 928 |
```
|
| 929 |
|
| 930 |
+
*Effects:* Equivalent to: `x.swap(y)`.
|
| 931 |
|
| 932 |
#### Member functions <a id="ostringstream.members">[[ostringstream.members]]</a>
|
| 933 |
|
| 934 |
``` cpp
|
| 935 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 936 |
```
|
| 937 |
|
| 938 |
*Returns:*
|
| 939 |
+
`const_cast<basic_stringbuf<charT, traits, Allocator>*>(addressof(sb))`.
|
| 940 |
|
| 941 |
``` cpp
|
| 942 |
+
basic_string<charT, traits, Allocator> str() const &;
|
| 943 |
```
|
| 944 |
|
| 945 |
+
*Effects:* Equivalent to: `return rdbuf()->str();`
|
| 946 |
+
|
| 947 |
+
``` cpp
|
| 948 |
+
template<class SAlloc>
|
| 949 |
+
basic_string<charT,traits,SAlloc> str(const SAlloc& sa) const;
|
| 950 |
+
```
|
| 951 |
+
|
| 952 |
+
*Effects:* Equivalent to: `return rdbuf()->str(sa);`
|
| 953 |
+
|
| 954 |
+
``` cpp
|
| 955 |
+
basic_string<charT,traits,Allocator> str() &&;
|
| 956 |
+
```
|
| 957 |
+
|
| 958 |
+
*Effects:* Equivalent to: `return std::move(*rdbuf()).str();`
|
| 959 |
+
|
| 960 |
+
``` cpp
|
| 961 |
+
basic_string_view<charT, traits> view() const noexcept;
|
| 962 |
+
```
|
| 963 |
+
|
| 964 |
+
*Effects:* Equivalent to: `return rdbuf()->view();`
|
| 965 |
|
| 966 |
``` cpp
|
| 967 |
void str(const basic_string<charT, traits, Allocator>& s);
|
| 968 |
```
|
| 969 |
|
| 970 |
+
*Effects:* Equivalent to: `rdbuf()->str(s);`
|
| 971 |
+
|
| 972 |
+
``` cpp
|
| 973 |
+
template<class SAlloc>
|
| 974 |
+
void str(const basic_string<charT, traits, SAlloc>& s);
|
| 975 |
+
```
|
| 976 |
+
|
| 977 |
+
*Effects:* Equivalent to: `rdbuf()->str(s);`
|
| 978 |
+
|
| 979 |
+
``` cpp
|
| 980 |
+
void str(basic_string<charT, traits, Allocator>&& s);
|
| 981 |
+
```
|
| 982 |
+
|
| 983 |
+
*Effects:* Equivalent to: `rdbuf()->str(std::move(s));`
|
| 984 |
|
| 985 |
### Class template `basic_stringstream` <a id="stringstream">[[stringstream]]</a>
|
| 986 |
|
| 987 |
``` cpp
|
| 988 |
namespace std {
|
|
|
|
| 996 |
using off_type = typename traits::off_type;
|
| 997 |
using traits_type = traits;
|
| 998 |
using allocator_type = Allocator;
|
| 999 |
|
| 1000 |
// [stringstream.cons], constructors
|
| 1001 |
+
basic_stringstream() : basic_stringstream(ios_base::out | ios_base::in) {}
|
| 1002 |
+
explicit basic_stringstream(ios_base::openmode which);
|
| 1003 |
explicit basic_stringstream(
|
| 1004 |
+
const basic_string<charT, traits, Allocator>& s,
|
| 1005 |
ios_base::openmode which = ios_base::out | ios_base::in);
|
| 1006 |
+
basic_stringstream(ios_base::openmode which, const Allocator& a);
|
| 1007 |
explicit basic_stringstream(
|
| 1008 |
+
basic_string<charT, traits, Allocator>&& s,
|
| 1009 |
ios_base::openmode which = ios_base::out | ios_base::in);
|
| 1010 |
+
template<class SAlloc>
|
| 1011 |
+
basic_stringstream(
|
| 1012 |
+
const basic_string<charT, traits, SAlloc>& s, const Allocator& a)
|
| 1013 |
+
: basic_stringstream(s, ios_base::out | ios_base::in, a) {}
|
| 1014 |
+
template<class SAlloc>
|
| 1015 |
+
basic_stringstream(
|
| 1016 |
+
const basic_string<charT, traits, SAlloc>& s,
|
| 1017 |
+
ios_base::openmode which, const Allocator& a);
|
| 1018 |
+
template<class SAlloc>
|
| 1019 |
+
explicit basic_stringstream(
|
| 1020 |
+
const basic_string<charT, traits, SAlloc>& s,
|
| 1021 |
+
ios_base::openmode which = ios_base::out | ios_base::in);
|
| 1022 |
+
basic_stringstream(const basic_stringstream&) = delete;
|
| 1023 |
basic_stringstream(basic_stringstream&& rhs);
|
| 1024 |
|
| 1025 |
// [stringstream.assign], assign and swap
|
| 1026 |
+
basic_stringstream& operator=(const basic_stringstream&) = delete;
|
| 1027 |
basic_stringstream& operator=(basic_stringstream&& rhs);
|
| 1028 |
void swap(basic_stringstream& rhs);
|
| 1029 |
|
| 1030 |
// [stringstream.members], members
|
| 1031 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 1032 |
+
|
| 1033 |
+
basic_string<charT, traits, Allocator> str() const &;
|
| 1034 |
+
template<class SAlloc>
|
| 1035 |
+
basic_string<charT,traits,SAlloc> str(const SAlloc& sa) const;
|
| 1036 |
+
basic_string<charT, traits, Allocator> str() &&;
|
| 1037 |
+
basic_string_view<charT, traits> view() const noexcept;
|
| 1038 |
+
|
| 1039 |
+
void str(const basic_string<charT, traits, Allocator>& s);
|
| 1040 |
+
template<class SAlloc>
|
| 1041 |
+
void str(const basic_string<charT, traits, SAlloc>& s);
|
| 1042 |
+
void str(basic_string<charT, traits, Allocator>&& s);
|
| 1043 |
|
| 1044 |
private:
|
| 1045 |
basic_stringbuf<charT, traits> sb; // exposition only
|
| 1046 |
};
|
| 1047 |
|
|
|
|
| 1058 |
associated sequence. For the sake of exposition, the maintained data is
|
| 1059 |
presented here as
|
| 1060 |
|
| 1061 |
- `sb`, the `stringbuf` object.
|
| 1062 |
|
| 1063 |
+
#### Constructors <a id="stringstream.cons">[[stringstream.cons]]</a>
|
| 1064 |
+
|
| 1065 |
+
``` cpp
|
| 1066 |
+
explicit basic_stringstream(ios_base::openmode which);
|
| 1067 |
+
```
|
| 1068 |
+
|
| 1069 |
+
*Effects:* Initializes the base class with
|
| 1070 |
+
`basic_iostream<charT, traits>(addressof(sb))` [[iostream.cons]] and
|
| 1071 |
+
`sb` with `basic_stringbuf<charT, traits, Allocator>(which)`.
|
| 1072 |
|
| 1073 |
``` cpp
|
| 1074 |
explicit basic_stringstream(
|
| 1075 |
+
const basic_string<charT, traits, Allocator>& s,
|
| 1076 |
ios_base::openmode which = ios_base::out | ios_base::in);
|
| 1077 |
```
|
| 1078 |
|
| 1079 |
+
*Effects:* Initializes the base class with
|
| 1080 |
+
`basic_iostream<charT, traits>(addressof(sb))` [[iostream.cons]] and
|
| 1081 |
+
`sb` with `basic_stringbuf<charT, traits, Allocator>(s, which)`.
|
| 1082 |
+
|
| 1083 |
+
``` cpp
|
| 1084 |
+
basic_stringstream(ios_base::openmode which, const Allocator& a);
|
| 1085 |
+
```
|
| 1086 |
+
|
| 1087 |
+
*Effects:* Initializes the base class with
|
| 1088 |
+
`basic_iostream<charT, traits>(addressof(sb))` [[iostream.cons]] and
|
| 1089 |
+
`sb` with `basic_stringbuf<charT, traits, Allocator>(which, a)`
|
| 1090 |
+
[[stringbuf.cons]].
|
| 1091 |
|
| 1092 |
``` cpp
|
| 1093 |
explicit basic_stringstream(
|
| 1094 |
+
basic_string<charT, traits, Allocator>&& s,
|
| 1095 |
ios_base::openmode which = ios_base::out | ios_base::in);
|
| 1096 |
```
|
| 1097 |
|
| 1098 |
+
*Effects:* Initializes the base class with
|
| 1099 |
+
`basic_iostream<charT, traits>(addressof(sb))` [[iostream.cons]] and
|
| 1100 |
+
`sb` with
|
| 1101 |
+
`basic_stringbuf<charT, traits, Allocator>(std::move(s), which)`
|
| 1102 |
+
[[stringbuf.cons]].
|
| 1103 |
+
|
| 1104 |
+
``` cpp
|
| 1105 |
+
template<class SAlloc>
|
| 1106 |
+
basic_stringstream(
|
| 1107 |
+
const basic_string<charT, traits, SAlloc>& s,
|
| 1108 |
+
ios_base::openmode which, const Allocator& a);
|
| 1109 |
+
```
|
| 1110 |
+
|
| 1111 |
+
*Effects:* Initializes the base class with
|
| 1112 |
+
`basic_iostream<charT, traits>(addressof(sb))` [[iostream.cons]] and
|
| 1113 |
+
`sb` with `basic_stringbuf<charT, traits, Allocator>(s, which, a)`
|
| 1114 |
+
[[stringbuf.cons]].
|
| 1115 |
+
|
| 1116 |
+
``` cpp
|
| 1117 |
+
template<class SAlloc>
|
| 1118 |
+
explicit basic_stringstream(
|
| 1119 |
+
const basic_string<charT, traits, SAlloc>& s,
|
| 1120 |
+
ios_base::openmode which = ios_base::out | ios_base::in);
|
| 1121 |
+
```
|
| 1122 |
+
|
| 1123 |
+
*Constraints:* `is_same_v<SAlloc,Allocator>` is `false`.
|
| 1124 |
+
|
| 1125 |
+
*Effects:* Initializes the base class with
|
| 1126 |
+
`basic_iostream<charT, traits>(addressof(sb))` [[iostream.cons]] and
|
| 1127 |
+
`sb` with `basic_stringbuf<charT, traits, Allocator>(s, which)`
|
| 1128 |
+
[[stringbuf.cons]].
|
| 1129 |
|
| 1130 |
``` cpp
|
| 1131 |
basic_stringstream(basic_stringstream&& rhs);
|
| 1132 |
```
|
| 1133 |
|
| 1134 |
*Effects:* Move constructs from the rvalue `rhs`. This is accomplished
|
| 1135 |
by move constructing the base class, and the contained
|
| 1136 |
+
`basic_stringbuf`. Then calls
|
| 1137 |
+
`basic_istream<charT, traits>::set_rdbuf(addressof(sb))` to install the
|
| 1138 |
+
contained `basic_stringbuf`.
|
| 1139 |
|
| 1140 |
+
#### Assignment and swap <a id="stringstream.assign">[[stringstream.assign]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1141 |
|
| 1142 |
``` cpp
|
| 1143 |
void swap(basic_stringstream& rhs);
|
| 1144 |
```
|
| 1145 |
|
| 1146 |
+
*Effects:* Equivalent to:
|
| 1147 |
+
|
| 1148 |
+
``` cpp
|
| 1149 |
+
basic_iostream<charT,traits>::swap(rhs);
|
| 1150 |
+
sb.swap(rhs.sb);
|
| 1151 |
+
```
|
| 1152 |
|
| 1153 |
``` cpp
|
| 1154 |
template<class charT, class traits, class Allocator>
|
| 1155 |
void swap(basic_stringstream<charT, traits, Allocator>& x,
|
| 1156 |
basic_stringstream<charT, traits, Allocator>& y);
|
| 1157 |
```
|
| 1158 |
|
| 1159 |
+
*Effects:* Equivalent to: `x.swap(y)`.
|
| 1160 |
|
| 1161 |
#### Member functions <a id="stringstream.members">[[stringstream.members]]</a>
|
| 1162 |
|
| 1163 |
``` cpp
|
| 1164 |
basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
| 1165 |
```
|
| 1166 |
|
| 1167 |
+
*Returns:*
|
| 1168 |
+
`const_cast<basic_stringbuf<charT, traits, Allocator>*>(addressof(sb))`.
|
| 1169 |
|
| 1170 |
``` cpp
|
| 1171 |
+
basic_string<charT, traits, Allocator> str() const &;
|
| 1172 |
```
|
| 1173 |
|
| 1174 |
+
*Effects:* Equivalent to: `return rdbuf()->str();`
|
| 1175 |
|
| 1176 |
``` cpp
|
| 1177 |
+
template<class SAlloc>
|
| 1178 |
+
basic_string<charT,traits,SAlloc> str(const SAlloc& sa) const;
|
| 1179 |
```
|
| 1180 |
|
| 1181 |
+
*Effects:* Equivalent to: `return rdbuf()->str(sa);`
|
| 1182 |
+
|
| 1183 |
+
``` cpp
|
| 1184 |
+
basic_string<charT,traits,Allocator> str() &&;
|
| 1185 |
+
```
|
| 1186 |
+
|
| 1187 |
+
*Effects:* Equivalent to: `return std::move(*rdbuf()).str();`
|
| 1188 |
+
|
| 1189 |
+
``` cpp
|
| 1190 |
+
basic_string_view<charT, traits> view() const noexcept;
|
| 1191 |
+
```
|
| 1192 |
+
|
| 1193 |
+
*Effects:* Equivalent to: `return rdbuf()->view();`
|
| 1194 |
+
|
| 1195 |
+
``` cpp
|
| 1196 |
+
void str(const basic_string<charT, traits, Allocator>& s);
|
| 1197 |
+
```
|
| 1198 |
+
|
| 1199 |
+
*Effects:* Equivalent to: `rdbuf()->str(s);`
|
| 1200 |
+
|
| 1201 |
+
``` cpp
|
| 1202 |
+
template<class SAlloc>
|
| 1203 |
+
void str(const basic_string<charT, traits, SAlloc>& s);
|
| 1204 |
+
```
|
| 1205 |
+
|
| 1206 |
+
*Effects:* Equivalent to: `rdbuf()->str(s);`
|
| 1207 |
+
|
| 1208 |
+
``` cpp
|
| 1209 |
+
void str(basic_string<charT, traits, Allocator>&& s);
|
| 1210 |
+
```
|
| 1211 |
+
|
| 1212 |
+
*Effects:* Equivalent to: `rdbuf()->str(std::move(s));`
|
| 1213 |
|