- tmp/tmplyrsirzh/{from.md → to.md} +126 -120
tmp/tmplyrsirzh/{from.md → to.md}
RENAMED
|
@@ -10,30 +10,30 @@ that inserts into stream rvalues.
|
|
| 10 |
namespace std {
|
| 11 |
template <class charT, class traits = char_traits<charT>>
|
| 12 |
class basic_ostream : virtual public basic_ios<charT, traits> {
|
| 13 |
public:
|
| 14 |
// types (inherited from basic_ios ([ios])):
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
-
// [ostream.cons]
|
| 22 |
explicit basic_ostream(basic_streambuf<char_type, traits>* sb);
|
| 23 |
virtual ~basic_ostream();
|
| 24 |
|
| 25 |
-
// [ostream::sentry]
|
| 26 |
class sentry;
|
| 27 |
|
| 28 |
-
// [ostream.formatted]
|
| 29 |
-
basic_ostream<charT,traits>&
|
| 30 |
-
basic_ostream<charT,traits>& (*pf)(basic_ostream<charT,traits>&));
|
| 31 |
-
basic_ostream<charT,traits>&
|
| 32 |
-
basic_ios<charT,traits>& (*pf)(basic_ios<charT,traits>&));
|
| 33 |
-
basic_ostream<charT,traits>&
|
| 34 |
-
ios_base& (*pf)(ios_base&));
|
| 35 |
|
| 36 |
basic_ostream<charT, traits>& operator<<(bool n);
|
| 37 |
basic_ostream<charT, traits>& operator<<(short n);
|
| 38 |
basic_ostream<charT, traits>& operator<<(unsigned short n);
|
| 39 |
basic_ostream<charT, traits>& operator<<(int n);
|
|
@@ -45,75 +45,65 @@ namespace std {
|
|
| 45 |
basic_ostream<charT, traits>& operator<<(float f);
|
| 46 |
basic_ostream<charT, traits>& operator<<(double f);
|
| 47 |
basic_ostream<charT, traits>& operator<<(long double f);
|
| 48 |
|
| 49 |
basic_ostream<charT, traits>& operator<<(const void* p);
|
| 50 |
-
basic_ostream<charT,traits>& operator<<(
|
| 51 |
-
|
| 52 |
|
| 53 |
-
// [ostream.unformatted]
|
| 54 |
basic_ostream<charT, traits>& put(char_type c);
|
| 55 |
basic_ostream<charT, traits>& write(const char_type* s, streamsize n);
|
| 56 |
|
| 57 |
basic_ostream<charT, traits>& flush();
|
| 58 |
|
| 59 |
-
// [ostream.seeks] seeks
|
| 60 |
pos_type tellp();
|
| 61 |
basic_ostream<charT, traits>& seekp(pos_type);
|
| 62 |
basic_ostream<charT, traits>& seekp(off_type, ios_base::seekdir);
|
|
|
|
| 63 |
protected:
|
|
|
|
| 64 |
basic_ostream(const basic_ostream& rhs) = delete;
|
| 65 |
basic_ostream(basic_ostream&& rhs);
|
| 66 |
|
| 67 |
-
// [ostream.assign]
|
| 68 |
basic_ostream& operator=(const basic_ostream& rhs) = delete;
|
| 69 |
basic_ostream& operator=(basic_ostream&& rhs);
|
| 70 |
void swap(basic_ostream& rhs);
|
| 71 |
};
|
| 72 |
|
| 73 |
-
// [ostream.inserters.character] character inserters
|
| 74 |
template<class charT, class traits>
|
| 75 |
-
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&,
|
| 76 |
-
charT);
|
| 77 |
template<class charT, class traits>
|
| 78 |
-
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&,
|
| 79 |
-
char);
|
| 80 |
template<class traits>
|
| 81 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&,
|
| 82 |
-
char);
|
| 83 |
|
| 84 |
-
// signed and unsigned
|
| 85 |
template<class traits>
|
| 86 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&,
|
| 87 |
-
signed char);
|
| 88 |
template<class traits>
|
| 89 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&,
|
| 90 |
-
unsigned char);
|
| 91 |
|
| 92 |
template<class charT, class traits>
|
| 93 |
-
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&,
|
| 94 |
-
const charT*);
|
| 95 |
template<class charT, class traits>
|
| 96 |
-
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&,
|
| 97 |
-
const char*);
|
| 98 |
template<class traits>
|
| 99 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&,
|
| 100 |
-
const char*);
|
| 101 |
|
| 102 |
-
// signed and unsigned
|
| 103 |
template<class traits>
|
| 104 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&,
|
| 105 |
-
const signed char*);
|
| 106 |
template<class traits>
|
| 107 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&,
|
| 108 |
-
const unsigned char*);
|
| 109 |
}
|
| 110 |
```
|
| 111 |
|
| 112 |
-
The class `basic_ostream` defines a number of member function
|
| 113 |
-
that assist in formatting and writing output to output
|
| 114 |
-
controlled by a stream buffer.
|
| 115 |
|
| 116 |
Two groups of member function signatures share common properties: the
|
| 117 |
*formatted output functions* (or *inserters*) and the *unformatted
|
| 118 |
output functions.* Both groups of output functions generate (or
|
| 119 |
*insert*) output *characters* by actions equivalent to calling
|
|
@@ -125,45 +115,55 @@ If one of these called functions throws an exception, then unless
|
|
| 125 |
explicitly noted otherwise the output function sets `badbit` in error
|
| 126 |
state. If `badbit` is on in `exceptions()`, the output function rethrows
|
| 127 |
the exception without completing its actions, otherwise it does not
|
| 128 |
throw anything and treat as an error.
|
| 129 |
|
| 130 |
-
#### `basic_ostream` constructors <a id="ostream.cons">[[ostream.cons]]</a>
|
| 131 |
|
| 132 |
``` cpp
|
| 133 |
explicit basic_ostream(basic_streambuf<charT, traits>* sb);
|
| 134 |
```
|
| 135 |
|
| 136 |
-
``
|
| 137 |
-
|
| 138 |
-
``
|
|
|
|
|
|
|
| 139 |
|
| 140 |
``` cpp
|
| 141 |
basic_ostream(basic_ostream&& rhs);
|
| 142 |
```
|
| 143 |
|
| 144 |
*Effects:* Move constructs from the rvalue `rhs`. This is accomplished
|
| 145 |
by default constructing the base class and calling
|
| 146 |
`basic_ios<charT, traits>::move(rhs)` to initialize the base class.
|
| 147 |
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
|
| 150 |
``` cpp
|
| 151 |
basic_ostream& operator=(basic_ostream&& rhs);
|
| 152 |
```
|
| 153 |
|
| 154 |
-
*Effects:* `swap(rhs)`.
|
| 155 |
|
| 156 |
*Returns:* `*this`.
|
| 157 |
|
| 158 |
``` cpp
|
| 159 |
void swap(basic_ostream& rhs);
|
| 160 |
```
|
| 161 |
|
| 162 |
*Effects:* Calls `basic_ios<charT, traits>::swap(rhs)`.
|
| 163 |
|
| 164 |
-
#### Class `basic_ostream::sentry` <a id="ostream::sentry">[[ostream::sentry]]</a>
|
| 165 |
|
| 166 |
``` cpp
|
| 167 |
namespace std {
|
| 168 |
template <class charT, class traits = char_traits<charT>>
|
| 169 |
class basic_ostream<charT, traits>::sentry {
|
|
@@ -185,45 +185,55 @@ exception safe prefix and suffix operations.
|
|
| 185 |
``` cpp
|
| 186 |
explicit sentry(basic_ostream<charT, traits>& os);
|
| 187 |
```
|
| 188 |
|
| 189 |
If `os.good()` is nonzero, prepares for formatted or unformatted output.
|
| 190 |
-
If `os.tie()` is not a null pointer, calls `os.tie()->flush()`.[^
|
| 191 |
|
| 192 |
If, after any preparation is completed, `os.good()` is `true`,
|
| 193 |
`ok_ == true` otherwise, `ok_ == false`. During preparation, the
|
| 194 |
constructor may call `setstate(failbit)` (which may throw
|
| 195 |
-
`ios_base::failure` ([[iostate.flags]]))[^
|
| 196 |
|
| 197 |
``` cpp
|
| 198 |
~sentry();
|
| 199 |
```
|
| 200 |
|
| 201 |
If
|
| 202 |
-
`(
|
| 203 |
is `true`, calls `os.rdbuf()->pubsync()`. If that function returns -1,
|
| 204 |
sets `badbit` in `os.rdstate()` without propagating an exception.
|
| 205 |
|
| 206 |
``` cpp
|
| 207 |
explicit operator bool() const;
|
| 208 |
```
|
| 209 |
|
| 210 |
*Effects:* Returns `ok_`.
|
| 211 |
|
| 212 |
-
#### `basic_ostream` seek members <a id="ostream.seeks">[[ostream.seeks]]</a>
|
| 213 |
|
| 214 |
Each seek member function begins execution by constructing an object of
|
| 215 |
class `sentry`. It returns by destroying the `sentry` object.
|
| 216 |
|
| 217 |
``` cpp
|
| 218 |
pos_type tellp();
|
| 219 |
```
|
| 220 |
|
|
|
|
|
|
|
|
|
|
| 221 |
``` cpp
|
| 222 |
basic_ostream<charT, traits>& seekp(pos_type pos);
|
| 223 |
```
|
| 224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
``` cpp
|
| 226 |
basic_ostream<charT, traits>& seekp(off_type off, ios_base::seekdir dir);
|
| 227 |
```
|
| 228 |
|
| 229 |
*Effects:* If `fail() != true`, executes
|
|
@@ -241,11 +251,11 @@ Each formatted output function begins execution by constructing an
|
|
| 241 |
object of class `sentry`. If this object returns `true` when converted
|
| 242 |
to a value of type `bool`, the function endeavors to generate the
|
| 243 |
requested output. If the generation fails, then the formatted output
|
| 244 |
function does `setstate(ios_base::failbit)`, which might throw an
|
| 245 |
exception. If an exception is thrown during output, then `ios::badbit`
|
| 246 |
-
is turned on[^
|
| 247 |
`(exceptions()&badbit) != 0` then the exception is rethrown. Whether or
|
| 248 |
not an exception is thrown, the `sentry` object is destroyed before
|
| 249 |
leaving the formatted output function. If no exception is thrown, the
|
| 250 |
result of the formatted output function is `*this`.
|
| 251 |
|
|
@@ -342,59 +352,57 @@ bool failed = use_facet<
|
|
| 342 |
The first argument provides an object of the `ostreambuf_iterator<>`
|
| 343 |
class which is an iterator for class `basic_ostream<>`. It bypasses
|
| 344 |
`ostream`s and uses `streambuf`s directly. Class `locale` relies on
|
| 345 |
these types as its interface to iostreams, since for flexibility it has
|
| 346 |
been abstracted away from direct dependence on `ostream`. The second
|
| 347 |
-
parameter is a reference to the base subobject of type `ios_base`.
|
| 348 |
-
provides formatting specifications such as field width, and a locale
|
| 349 |
from which to obtain other facets. If `failed` is `true` then does
|
| 350 |
`setstate(badbit)`, which may throw an exception, and returns.
|
| 351 |
|
| 352 |
*Returns:* `*this`.
|
| 353 |
|
| 354 |
##### `basic_ostream::operator<<` <a id="ostream.inserters">[[ostream.inserters]]</a>
|
| 355 |
|
| 356 |
``` cpp
|
| 357 |
-
basic_ostream<charT,traits>&
|
| 358 |
-
|
| 359 |
```
|
| 360 |
|
| 361 |
*Effects:* None. Does not behave as a formatted output function (as
|
| 362 |
described in [[ostream.formatted.reqmts]]).
|
| 363 |
|
| 364 |
-
*Returns:* `pf(*this)`.[^
|
| 365 |
|
| 366 |
``` cpp
|
| 367 |
-
basic_ostream<charT,traits>&
|
| 368 |
-
|
| 369 |
```
|
| 370 |
|
| 371 |
*Effects:* Calls `pf(*this)`. This inserter does not behave as a
|
| 372 |
formatted output function (as described
|
| 373 |
in [[ostream.formatted.reqmts]]).
|
| 374 |
|
| 375 |
-
*Returns:* `*this`.[^
|
| 376 |
|
| 377 |
``` cpp
|
| 378 |
-
basic_ostream<charT,traits>& operator<<
|
| 379 |
-
(ios_base& (*pf)(ios_base&));
|
| 380 |
```
|
| 381 |
|
| 382 |
*Effects:* Calls `pf(*this)`. This inserter does not behave as a
|
| 383 |
formatted output function (as described
|
| 384 |
in [[ostream.formatted.reqmts]]).
|
| 385 |
|
| 386 |
*Returns:* `*this`.
|
| 387 |
|
| 388 |
``` cpp
|
| 389 |
-
basic_ostream<charT,traits>& operator<<
|
| 390 |
-
(basic_streambuf<charT,traits>* sb);
|
| 391 |
```
|
| 392 |
|
| 393 |
-
*Effects:* Behaves as an unformatted output function
|
| 394 |
-
|
| 395 |
-
|
| 396 |
`ios_base::failure`).
|
| 397 |
|
| 398 |
Gets characters from `sb` and inserts them in `*this`. Characters are
|
| 399 |
read from `sb` and inserted until any of the following occurs:
|
| 400 |
|
|
@@ -409,55 +417,58 @@ exception was thrown while extracting a character, the function sets
|
|
| 409 |
`failbit` in error state, and if `failbit` is on in `exceptions()` the
|
| 410 |
caught exception is rethrown.
|
| 411 |
|
| 412 |
*Returns:* `*this`.
|
| 413 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 414 |
##### Character inserter function templates <a id="ostream.inserters.character">[[ostream.inserters.character]]</a>
|
| 415 |
|
| 416 |
``` cpp
|
| 417 |
template<class charT, class traits>
|
| 418 |
-
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out,
|
| 419 |
-
charT c);
|
| 420 |
template<class charT, class traits>
|
| 421 |
-
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out,
|
| 422 |
-
char c);
|
| 423 |
// specialization
|
| 424 |
template<class traits>
|
| 425 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out,
|
| 426 |
-
char c);
|
| 427 |
// signed and unsigned
|
| 428 |
template<class traits>
|
| 429 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out,
|
| 430 |
-
signed char c);
|
| 431 |
template<class traits>
|
| 432 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out,
|
| 433 |
-
unsigned char c);
|
| 434 |
```
|
| 435 |
|
| 436 |
-
*Effects:* Behaves as a formatted output
|
| 437 |
-
(
|
| 438 |
-
sequence `seq`. If `c` has type `char` and the character type
|
| 439 |
-
stream is not `char`, then `seq` consists of `out.widen(c)`;
|
| 440 |
-
`seq` consists of `c`. Determines padding for `seq` as
|
| 441 |
-
in [[ostream.formatted.reqmts]]. Inserts `seq` into `out`.
|
| 442 |
-
`os.width(0)`.
|
| 443 |
|
| 444 |
*Returns:* `out`.
|
| 445 |
|
| 446 |
``` cpp
|
| 447 |
template<class charT, class traits>
|
| 448 |
-
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out,
|
| 449 |
-
const charT* s);
|
| 450 |
template<class charT, class traits>
|
| 451 |
-
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out,
|
| 452 |
-
const char* s);
|
| 453 |
template<class traits>
|
| 454 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out,
|
| 455 |
-
const char* s);
|
| 456 |
template<class traits>
|
| 457 |
-
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out,
|
| 458 |
-
const signed char* s);
|
| 459 |
template<class traits>
|
| 460 |
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out,
|
| 461 |
const unsigned char* s);
|
| 462 |
```
|
| 463 |
|
|
@@ -472,11 +483,11 @@ would be computed as if by:
|
|
| 472 |
- `traits::length(s)` for the overload where the first argument is of
|
| 473 |
type `basic_ostream<charT, traits>&` and the second is of type
|
| 474 |
`const charT*`, and also for the overload where the first argument is
|
| 475 |
of type `basic_ostream<char, traits>&` and the second is of type
|
| 476 |
`const char*`,
|
| 477 |
-
- `
|
| 478 |
argument is of type `basic_ostream<charT, traits>&` and the second is
|
| 479 |
of type `const char*`,
|
| 480 |
- `traits::length(reinterpret_cast<const char*>(s))` for the other two
|
| 481 |
overloads.
|
| 482 |
|
|
@@ -490,23 +501,23 @@ in [[ostream.formatted.reqmts]]. Inserts `seq` into `out`. Calls
|
|
| 490 |
|
| 491 |
Each unformatted output function begins execution by constructing an
|
| 492 |
object of class `sentry`. If this object returns `true`, while
|
| 493 |
converting to a value of type `bool`, the function endeavors to generate
|
| 494 |
the requested output. If an exception is thrown during output, then
|
| 495 |
-
`ios::badbit` is turned on[^
|
| 496 |
`(exceptions() & badbit) != 0` then the exception is rethrown. In any
|
| 497 |
case, the unformatted output function ends by destroying the sentry
|
| 498 |
object, then, if no exception was thrown, returning the value specified
|
| 499 |
for the unformatted output function.
|
| 500 |
|
| 501 |
``` cpp
|
| 502 |
basic_ostream<charT, traits>& put(char_type c);
|
| 503 |
```
|
| 504 |
|
| 505 |
*Effects:* Behaves as an unformatted output function (as described
|
| 506 |
-
|
| 507 |
-
|
| 508 |
|
| 509 |
Otherwise, calls `setstate(badbit)` (which may throw
|
| 510 |
`ios_base::failure` ([[iostate.flags]])).
|
| 511 |
|
| 512 |
*Returns:* `*this`.
|
|
@@ -514,14 +525,14 @@ Otherwise, calls `setstate(badbit)` (which may throw
|
|
| 514 |
``` cpp
|
| 515 |
basic_ostream& write(const char_type* s, streamsize n);
|
| 516 |
```
|
| 517 |
|
| 518 |
*Effects:* Behaves as an unformatted output function (as described
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
|
| 524 |
- `n` characters are inserted;
|
| 525 |
- inserting in the output sequence fails (in which case the function
|
| 526 |
calls `setstate(badbit)`, which may throw
|
| 527 |
`ios_base::failure` ([[iostate.flags]])).
|
|
@@ -531,63 +542,58 @@ inserted until either of the following occurs:
|
|
| 531 |
``` cpp
|
| 532 |
basic_ostream& flush();
|
| 533 |
```
|
| 534 |
|
| 535 |
*Effects:* Behaves as an unformatted output function (as described
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
`
|
| 540 |
-
`setstate(badbit)` (which may throw
|
| 541 |
`ios_base::failure` ([[iostate.flags]])). Otherwise, if the sentry
|
| 542 |
object returns `false`, does nothing.
|
| 543 |
|
| 544 |
*Returns:* `*this`.
|
| 545 |
|
| 546 |
#### Standard `basic_ostream` manipulators <a id="ostream.manip">[[ostream.manip]]</a>
|
| 547 |
|
| 548 |
``` cpp
|
| 549 |
-
namespace std {
|
| 550 |
template <class charT, class traits>
|
| 551 |
basic_ostream<charT, traits>& endl(basic_ostream<charT, traits>& os);
|
| 552 |
-
}
|
| 553 |
```
|
| 554 |
|
| 555 |
*Effects:* Calls `os.put(os.widen(’\n’))`, then `os.flush()`.
|
| 556 |
|
| 557 |
*Returns:* `os`.
|
| 558 |
|
| 559 |
``` cpp
|
| 560 |
-
namespace std {
|
| 561 |
template <class charT, class traits>
|
| 562 |
basic_ostream<charT, traits>& ends(basic_ostream<charT, traits>& os);
|
| 563 |
-
}
|
| 564 |
```
|
| 565 |
|
| 566 |
*Effects:* Inserts a null character into the output sequence: calls
|
| 567 |
`os.put(charT())`.
|
| 568 |
|
| 569 |
*Returns:* `os`.
|
| 570 |
|
| 571 |
``` cpp
|
| 572 |
-
namespace std {
|
| 573 |
template <class charT, class traits>
|
| 574 |
basic_ostream<charT, traits>& flush(basic_ostream<charT, traits>& os);
|
| 575 |
-
}
|
| 576 |
```
|
| 577 |
|
| 578 |
*Effects:* Calls `os.flush()`.
|
| 579 |
|
| 580 |
*Returns:* `os`.
|
| 581 |
|
| 582 |
#### Rvalue stream insertion <a id="ostream.rvalue">[[ostream.rvalue]]</a>
|
| 583 |
|
| 584 |
``` cpp
|
| 585 |
template <class charT, class traits, class T>
|
| 586 |
-
basic_ostream<charT, traits>&
|
| 587 |
-
operator<<(basic_ostream<charT, traits>&& os, const T& x);
|
| 588 |
```
|
| 589 |
|
| 590 |
-
*Effects:* `os << x`
|
| 591 |
|
| 592 |
-
*Returns:* `os`
|
|
|
|
|
|
|
|
|
|
| 593 |
|
|
|
|
| 10 |
namespace std {
|
| 11 |
template <class charT, class traits = char_traits<charT>>
|
| 12 |
class basic_ostream : virtual public basic_ios<charT, traits> {
|
| 13 |
public:
|
| 14 |
// types (inherited from basic_ios ([ios])):
|
| 15 |
+
using char_type = charT;
|
| 16 |
+
using int_type = typename traits::int_type;
|
| 17 |
+
using pos_type = typename traits::pos_type;
|
| 18 |
+
using off_type = typename traits::off_type;
|
| 19 |
+
using traits_type = traits;
|
| 20 |
|
| 21 |
+
// [ostream.cons], constructor/destructor
|
| 22 |
explicit basic_ostream(basic_streambuf<char_type, traits>* sb);
|
| 23 |
virtual ~basic_ostream();
|
| 24 |
|
| 25 |
+
// [ostream::sentry], prefix/suffix
|
| 26 |
class sentry;
|
| 27 |
|
| 28 |
+
// [ostream.formatted], formatted output
|
| 29 |
+
basic_ostream<charT, traits>&
|
| 30 |
+
operator<<(basic_ostream<charT, traits>& (*pf)(basic_ostream<charT, traits>&));
|
| 31 |
+
basic_ostream<charT, traits>&
|
| 32 |
+
operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT, traits>&));
|
| 33 |
+
basic_ostream<charT, traits>&
|
| 34 |
+
operator<<(ios_base& (*pf)(ios_base&));
|
| 35 |
|
| 36 |
basic_ostream<charT, traits>& operator<<(bool n);
|
| 37 |
basic_ostream<charT, traits>& operator<<(short n);
|
| 38 |
basic_ostream<charT, traits>& operator<<(unsigned short n);
|
| 39 |
basic_ostream<charT, traits>& operator<<(int n);
|
|
|
|
| 45 |
basic_ostream<charT, traits>& operator<<(float f);
|
| 46 |
basic_ostream<charT, traits>& operator<<(double f);
|
| 47 |
basic_ostream<charT, traits>& operator<<(long double f);
|
| 48 |
|
| 49 |
basic_ostream<charT, traits>& operator<<(const void* p);
|
| 50 |
+
basic_ostream<charT, traits>& operator<<(nullptr_t);
|
| 51 |
+
basic_ostream<charT, traits>& operator<<(basic_streambuf<char_type, traits>* sb);
|
| 52 |
|
| 53 |
+
// [ostream.unformatted], unformatted output
|
| 54 |
basic_ostream<charT, traits>& put(char_type c);
|
| 55 |
basic_ostream<charT, traits>& write(const char_type* s, streamsize n);
|
| 56 |
|
| 57 |
basic_ostream<charT, traits>& flush();
|
| 58 |
|
| 59 |
+
// [ostream.seeks], seeks
|
| 60 |
pos_type tellp();
|
| 61 |
basic_ostream<charT, traits>& seekp(pos_type);
|
| 62 |
basic_ostream<charT, traits>& seekp(off_type, ios_base::seekdir);
|
| 63 |
+
|
| 64 |
protected:
|
| 65 |
+
// [ostream.cons], copy/move constructor
|
| 66 |
basic_ostream(const basic_ostream& rhs) = delete;
|
| 67 |
basic_ostream(basic_ostream&& rhs);
|
| 68 |
|
| 69 |
+
// [ostream.assign], assign and swap
|
| 70 |
basic_ostream& operator=(const basic_ostream& rhs) = delete;
|
| 71 |
basic_ostream& operator=(basic_ostream&& rhs);
|
| 72 |
void swap(basic_ostream& rhs);
|
| 73 |
};
|
| 74 |
|
| 75 |
+
// [ostream.inserters.character], character inserters
|
| 76 |
template<class charT, class traits>
|
| 77 |
+
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&, charT);
|
|
|
|
| 78 |
template<class charT, class traits>
|
| 79 |
+
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&, char);
|
|
|
|
| 80 |
template<class traits>
|
| 81 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char);
|
|
|
|
| 82 |
|
|
|
|
| 83 |
template<class traits>
|
| 84 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, signed char);
|
|
|
|
| 85 |
template<class traits>
|
| 86 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, unsigned char);
|
|
|
|
| 87 |
|
| 88 |
template<class charT, class traits>
|
| 89 |
+
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&, const charT*);
|
|
|
|
| 90 |
template<class charT, class traits>
|
| 91 |
+
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&, const char*);
|
|
|
|
| 92 |
template<class traits>
|
| 93 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char*);
|
|
|
|
| 94 |
|
|
|
|
| 95 |
template<class traits>
|
| 96 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const signed char*);
|
|
|
|
| 97 |
template<class traits>
|
| 98 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const unsigned char*);
|
|
|
|
| 99 |
}
|
| 100 |
```
|
| 101 |
|
| 102 |
+
The class template `basic_ostream` defines a number of member function
|
| 103 |
+
signatures that assist in formatting and writing output to output
|
| 104 |
+
sequences controlled by a stream buffer.
|
| 105 |
|
| 106 |
Two groups of member function signatures share common properties: the
|
| 107 |
*formatted output functions* (or *inserters*) and the *unformatted
|
| 108 |
output functions.* Both groups of output functions generate (or
|
| 109 |
*insert*) output *characters* by actions equivalent to calling
|
|
|
|
| 115 |
explicitly noted otherwise the output function sets `badbit` in error
|
| 116 |
state. If `badbit` is on in `exceptions()`, the output function rethrows
|
| 117 |
the exception without completing its actions, otherwise it does not
|
| 118 |
throw anything and treat as an error.
|
| 119 |
|
| 120 |
+
##### `basic_ostream` constructors <a id="ostream.cons">[[ostream.cons]]</a>
|
| 121 |
|
| 122 |
``` cpp
|
| 123 |
explicit basic_ostream(basic_streambuf<charT, traits>* sb);
|
| 124 |
```
|
| 125 |
|
| 126 |
+
*Effects:* Constructs an object of class `basic_ostream`, initializing
|
| 127 |
+
the base class subobject with
|
| 128 |
+
`basic_ios<charT, traits>::init(sb)` ([[basic.ios.cons]]).
|
| 129 |
+
|
| 130 |
+
*Postconditions:* `rdbuf() == sb`.
|
| 131 |
|
| 132 |
``` cpp
|
| 133 |
basic_ostream(basic_ostream&& rhs);
|
| 134 |
```
|
| 135 |
|
| 136 |
*Effects:* Move constructs from the rvalue `rhs`. This is accomplished
|
| 137 |
by default constructing the base class and calling
|
| 138 |
`basic_ios<charT, traits>::move(rhs)` to initialize the base class.
|
| 139 |
|
| 140 |
+
``` cpp
|
| 141 |
+
virtual ~basic_ostream();
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
*Effects:* Destroys an object of class `basic_ostream`.
|
| 145 |
+
|
| 146 |
+
*Remarks:* Does not perform any operations on `rdbuf()`.
|
| 147 |
+
|
| 148 |
+
##### Class `basic_ostream` assign and swap <a id="ostream.assign">[[ostream.assign]]</a>
|
| 149 |
|
| 150 |
``` cpp
|
| 151 |
basic_ostream& operator=(basic_ostream&& rhs);
|
| 152 |
```
|
| 153 |
|
| 154 |
+
*Effects:* As if by `swap(rhs)`.
|
| 155 |
|
| 156 |
*Returns:* `*this`.
|
| 157 |
|
| 158 |
``` cpp
|
| 159 |
void swap(basic_ostream& rhs);
|
| 160 |
```
|
| 161 |
|
| 162 |
*Effects:* Calls `basic_ios<charT, traits>::swap(rhs)`.
|
| 163 |
|
| 164 |
+
##### Class `basic_ostream::sentry` <a id="ostream::sentry">[[ostream::sentry]]</a>
|
| 165 |
|
| 166 |
``` cpp
|
| 167 |
namespace std {
|
| 168 |
template <class charT, class traits = char_traits<charT>>
|
| 169 |
class basic_ostream<charT, traits>::sentry {
|
|
|
|
| 185 |
``` cpp
|
| 186 |
explicit sentry(basic_ostream<charT, traits>& os);
|
| 187 |
```
|
| 188 |
|
| 189 |
If `os.good()` is nonzero, prepares for formatted or unformatted output.
|
| 190 |
+
If `os.tie()` is not a null pointer, calls `os.tie()->flush()`.[^31]
|
| 191 |
|
| 192 |
If, after any preparation is completed, `os.good()` is `true`,
|
| 193 |
`ok_ == true` otherwise, `ok_ == false`. During preparation, the
|
| 194 |
constructor may call `setstate(failbit)` (which may throw
|
| 195 |
+
`ios_base::failure` ([[iostate.flags]]))[^32]
|
| 196 |
|
| 197 |
``` cpp
|
| 198 |
~sentry();
|
| 199 |
```
|
| 200 |
|
| 201 |
If
|
| 202 |
+
`(os.flags() & ios_base::unitbuf) && !uncaught_exceptions() && os.good()`
|
| 203 |
is `true`, calls `os.rdbuf()->pubsync()`. If that function returns -1,
|
| 204 |
sets `badbit` in `os.rdstate()` without propagating an exception.
|
| 205 |
|
| 206 |
``` cpp
|
| 207 |
explicit operator bool() const;
|
| 208 |
```
|
| 209 |
|
| 210 |
*Effects:* Returns `ok_`.
|
| 211 |
|
| 212 |
+
##### `basic_ostream` seek members <a id="ostream.seeks">[[ostream.seeks]]</a>
|
| 213 |
|
| 214 |
Each seek member function begins execution by constructing an object of
|
| 215 |
class `sentry`. It returns by destroying the `sentry` object.
|
| 216 |
|
| 217 |
``` cpp
|
| 218 |
pos_type tellp();
|
| 219 |
```
|
| 220 |
|
| 221 |
+
*Returns:* If `fail() != false`, returns `pos_type(-1)` to indicate
|
| 222 |
+
failure. Otherwise, returns `rdbuf()->pubseekoff(0, cur, out)`.
|
| 223 |
+
|
| 224 |
``` cpp
|
| 225 |
basic_ostream<charT, traits>& seekp(pos_type pos);
|
| 226 |
```
|
| 227 |
|
| 228 |
+
*Effects:* If `fail() != true`, executes
|
| 229 |
+
`rdbuf()->pubseekpos(pos, ios_base::out)`. In case of failure, the
|
| 230 |
+
function calls `setstate(failbit)` (which may throw
|
| 231 |
+
`ios_base::failure`).
|
| 232 |
+
|
| 233 |
+
*Returns:* `*this`.
|
| 234 |
+
|
| 235 |
``` cpp
|
| 236 |
basic_ostream<charT, traits>& seekp(off_type off, ios_base::seekdir dir);
|
| 237 |
```
|
| 238 |
|
| 239 |
*Effects:* If `fail() != true`, executes
|
|
|
|
| 251 |
object of class `sentry`. If this object returns `true` when converted
|
| 252 |
to a value of type `bool`, the function endeavors to generate the
|
| 253 |
requested output. If the generation fails, then the formatted output
|
| 254 |
function does `setstate(ios_base::failbit)`, which might throw an
|
| 255 |
exception. If an exception is thrown during output, then `ios::badbit`
|
| 256 |
+
is turned on[^33] in `*this`’s error state. If
|
| 257 |
`(exceptions()&badbit) != 0` then the exception is rethrown. Whether or
|
| 258 |
not an exception is thrown, the `sentry` object is destroyed before
|
| 259 |
leaving the formatted output function. If no exception is thrown, the
|
| 260 |
result of the formatted output function is `*this`.
|
| 261 |
|
|
|
|
| 352 |
The first argument provides an object of the `ostreambuf_iterator<>`
|
| 353 |
class which is an iterator for class `basic_ostream<>`. It bypasses
|
| 354 |
`ostream`s and uses `streambuf`s directly. Class `locale` relies on
|
| 355 |
these types as its interface to iostreams, since for flexibility it has
|
| 356 |
been abstracted away from direct dependence on `ostream`. The second
|
| 357 |
+
parameter is a reference to the base class subobject of type `ios_base`.
|
| 358 |
+
It provides formatting specifications such as field width, and a locale
|
| 359 |
from which to obtain other facets. If `failed` is `true` then does
|
| 360 |
`setstate(badbit)`, which may throw an exception, and returns.
|
| 361 |
|
| 362 |
*Returns:* `*this`.
|
| 363 |
|
| 364 |
##### `basic_ostream::operator<<` <a id="ostream.inserters">[[ostream.inserters]]</a>
|
| 365 |
|
| 366 |
``` cpp
|
| 367 |
+
basic_ostream<charT, traits>&
|
| 368 |
+
operator<<(basic_ostream<charT, traits>& (*pf)(basic_ostream<charT, traits>&));
|
| 369 |
```
|
| 370 |
|
| 371 |
*Effects:* None. Does not behave as a formatted output function (as
|
| 372 |
described in [[ostream.formatted.reqmts]]).
|
| 373 |
|
| 374 |
+
*Returns:* `pf(*this)`.[^34]
|
| 375 |
|
| 376 |
``` cpp
|
| 377 |
+
basic_ostream<charT, traits>&
|
| 378 |
+
operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT, traits>&));
|
| 379 |
```
|
| 380 |
|
| 381 |
*Effects:* Calls `pf(*this)`. This inserter does not behave as a
|
| 382 |
formatted output function (as described
|
| 383 |
in [[ostream.formatted.reqmts]]).
|
| 384 |
|
| 385 |
+
*Returns:* `*this`.[^35]
|
| 386 |
|
| 387 |
``` cpp
|
| 388 |
+
basic_ostream<charT, traits>& operator<<(ios_base& (*pf)(ios_base&));
|
|
|
|
| 389 |
```
|
| 390 |
|
| 391 |
*Effects:* Calls `pf(*this)`. This inserter does not behave as a
|
| 392 |
formatted output function (as described
|
| 393 |
in [[ostream.formatted.reqmts]]).
|
| 394 |
|
| 395 |
*Returns:* `*this`.
|
| 396 |
|
| 397 |
``` cpp
|
| 398 |
+
basic_ostream<charT, traits>& operator<<(basic_streambuf<charT, traits>* sb);
|
|
|
|
| 399 |
```
|
| 400 |
|
| 401 |
+
*Effects:* Behaves as an unformatted output function
|
| 402 |
+
([[ostream.unformatted]]). After the sentry object is constructed, if
|
| 403 |
+
`sb` is null calls `setstate(badbit)` (which may throw
|
| 404 |
`ios_base::failure`).
|
| 405 |
|
| 406 |
Gets characters from `sb` and inserts them in `*this`. Characters are
|
| 407 |
read from `sb` and inserted until any of the following occurs:
|
| 408 |
|
|
|
|
| 417 |
`failbit` in error state, and if `failbit` is on in `exceptions()` the
|
| 418 |
caught exception is rethrown.
|
| 419 |
|
| 420 |
*Returns:* `*this`.
|
| 421 |
|
| 422 |
+
``` cpp
|
| 423 |
+
basic_ostream<charT, traits>& operator<<(nullptr_t);
|
| 424 |
+
```
|
| 425 |
+
|
| 426 |
+
*Effects:* Equivalent to:
|
| 427 |
+
|
| 428 |
+
``` cpp
|
| 429 |
+
return *this << s;
|
| 430 |
+
```
|
| 431 |
+
|
| 432 |
+
where `s` is an *implementation-defined* NTCTS ([[defns.ntcts]]).
|
| 433 |
+
|
| 434 |
##### Character inserter function templates <a id="ostream.inserters.character">[[ostream.inserters.character]]</a>
|
| 435 |
|
| 436 |
``` cpp
|
| 437 |
template<class charT, class traits>
|
| 438 |
+
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& out, charT c);
|
|
|
|
| 439 |
template<class charT, class traits>
|
| 440 |
+
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& out, char c);
|
|
|
|
| 441 |
// specialization
|
| 442 |
template<class traits>
|
| 443 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, char c);
|
|
|
|
| 444 |
// signed and unsigned
|
| 445 |
template<class traits>
|
| 446 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, signed char c);
|
|
|
|
| 447 |
template<class traits>
|
| 448 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, unsigned char c);
|
|
|
|
| 449 |
```
|
| 450 |
|
| 451 |
+
*Effects:* Behaves as a formatted output
|
| 452 |
+
function ([[ostream.formatted.reqmts]]) of `out`. Constructs a
|
| 453 |
+
character sequence `seq`. If `c` has type `char` and the character type
|
| 454 |
+
of the stream is not `char`, then `seq` consists of `out.widen(c)`;
|
| 455 |
+
otherwise `seq` consists of `c`. Determines padding for `seq` as
|
| 456 |
+
described in [[ostream.formatted.reqmts]]. Inserts `seq` into `out`.
|
| 457 |
+
Calls `os.width(0)`.
|
| 458 |
|
| 459 |
*Returns:* `out`.
|
| 460 |
|
| 461 |
``` cpp
|
| 462 |
template<class charT, class traits>
|
| 463 |
+
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& out, const charT* s);
|
|
|
|
| 464 |
template<class charT, class traits>
|
| 465 |
+
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& out, const char* s);
|
|
|
|
| 466 |
template<class traits>
|
| 467 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, const char* s);
|
|
|
|
| 468 |
template<class traits>
|
| 469 |
+
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, const signed char* s);
|
|
|
|
| 470 |
template<class traits>
|
| 471 |
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out,
|
| 472 |
const unsigned char* s);
|
| 473 |
```
|
| 474 |
|
|
|
|
| 483 |
- `traits::length(s)` for the overload where the first argument is of
|
| 484 |
type `basic_ostream<charT, traits>&` and the second is of type
|
| 485 |
`const charT*`, and also for the overload where the first argument is
|
| 486 |
of type `basic_ostream<char, traits>&` and the second is of type
|
| 487 |
`const char*`,
|
| 488 |
+
- `char_traits<char>::length(s)` for the overload where the first
|
| 489 |
argument is of type `basic_ostream<charT, traits>&` and the second is
|
| 490 |
of type `const char*`,
|
| 491 |
- `traits::length(reinterpret_cast<const char*>(s))` for the other two
|
| 492 |
overloads.
|
| 493 |
|
|
|
|
| 501 |
|
| 502 |
Each unformatted output function begins execution by constructing an
|
| 503 |
object of class `sentry`. If this object returns `true`, while
|
| 504 |
converting to a value of type `bool`, the function endeavors to generate
|
| 505 |
the requested output. If an exception is thrown during output, then
|
| 506 |
+
`ios::badbit` is turned on[^36] in `*this`’s error state. If
|
| 507 |
`(exceptions() & badbit) != 0` then the exception is rethrown. In any
|
| 508 |
case, the unformatted output function ends by destroying the sentry
|
| 509 |
object, then, if no exception was thrown, returning the value specified
|
| 510 |
for the unformatted output function.
|
| 511 |
|
| 512 |
``` cpp
|
| 513 |
basic_ostream<charT, traits>& put(char_type c);
|
| 514 |
```
|
| 515 |
|
| 516 |
*Effects:* Behaves as an unformatted output function (as described
|
| 517 |
+
above). After constructing a sentry object, inserts the character `c`,
|
| 518 |
+
if possible.[^37]
|
| 519 |
|
| 520 |
Otherwise, calls `setstate(badbit)` (which may throw
|
| 521 |
`ios_base::failure` ([[iostate.flags]])).
|
| 522 |
|
| 523 |
*Returns:* `*this`.
|
|
|
|
| 525 |
``` cpp
|
| 526 |
basic_ostream& write(const char_type* s, streamsize n);
|
| 527 |
```
|
| 528 |
|
| 529 |
*Effects:* Behaves as an unformatted output function (as described
|
| 530 |
+
above). After constructing a sentry object, obtains characters to insert
|
| 531 |
+
from successive locations of an array whose first element is designated
|
| 532 |
+
by `s`.[^38] Characters are inserted until either of the following
|
| 533 |
+
occurs:
|
| 534 |
|
| 535 |
- `n` characters are inserted;
|
| 536 |
- inserting in the output sequence fails (in which case the function
|
| 537 |
calls `setstate(badbit)`, which may throw
|
| 538 |
`ios_base::failure` ([[iostate.flags]])).
|
|
|
|
| 542 |
``` cpp
|
| 543 |
basic_ostream& flush();
|
| 544 |
```
|
| 545 |
|
| 546 |
*Effects:* Behaves as an unformatted output function (as described
|
| 547 |
+
above). If `rdbuf()` is not a null pointer, constructs a sentry object.
|
| 548 |
+
If this object returns `true` when converted to a value of type `bool`
|
| 549 |
+
the function calls `rdbuf()->pubsync()`. If that function returns -1
|
| 550 |
+
calls `setstate(badbit)` (which may throw
|
|
|
|
| 551 |
`ios_base::failure` ([[iostate.flags]])). Otherwise, if the sentry
|
| 552 |
object returns `false`, does nothing.
|
| 553 |
|
| 554 |
*Returns:* `*this`.
|
| 555 |
|
| 556 |
#### Standard `basic_ostream` manipulators <a id="ostream.manip">[[ostream.manip]]</a>
|
| 557 |
|
| 558 |
``` cpp
|
|
|
|
| 559 |
template <class charT, class traits>
|
| 560 |
basic_ostream<charT, traits>& endl(basic_ostream<charT, traits>& os);
|
|
|
|
| 561 |
```
|
| 562 |
|
| 563 |
*Effects:* Calls `os.put(os.widen(’\n’))`, then `os.flush()`.
|
| 564 |
|
| 565 |
*Returns:* `os`.
|
| 566 |
|
| 567 |
``` cpp
|
|
|
|
| 568 |
template <class charT, class traits>
|
| 569 |
basic_ostream<charT, traits>& ends(basic_ostream<charT, traits>& os);
|
|
|
|
| 570 |
```
|
| 571 |
|
| 572 |
*Effects:* Inserts a null character into the output sequence: calls
|
| 573 |
`os.put(charT())`.
|
| 574 |
|
| 575 |
*Returns:* `os`.
|
| 576 |
|
| 577 |
``` cpp
|
|
|
|
| 578 |
template <class charT, class traits>
|
| 579 |
basic_ostream<charT, traits>& flush(basic_ostream<charT, traits>& os);
|
|
|
|
| 580 |
```
|
| 581 |
|
| 582 |
*Effects:* Calls `os.flush()`.
|
| 583 |
|
| 584 |
*Returns:* `os`.
|
| 585 |
|
| 586 |
#### Rvalue stream insertion <a id="ostream.rvalue">[[ostream.rvalue]]</a>
|
| 587 |
|
| 588 |
``` cpp
|
| 589 |
template <class charT, class traits, class T>
|
| 590 |
+
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&& os, const T& x);
|
|
|
|
| 591 |
```
|
| 592 |
|
| 593 |
+
*Effects:* As if by: `os << x;`
|
| 594 |
|
| 595 |
+
*Returns:* `os`.
|
| 596 |
+
|
| 597 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 598 |
+
unless the expression `os << x` is well-formed.
|
| 599 |
|