- tmp/tmps465kd98/{from.md → to.md} +116 -97
tmp/tmps465kd98/{from.md → to.md}
RENAMED
|
@@ -2,19 +2,23 @@
|
|
| 2 |
|
| 3 |
To make it possible for algorithmic templates to work directly with
|
| 4 |
input/output streams, appropriate iterator-like class templates are
|
| 5 |
provided.
|
| 6 |
|
|
|
|
|
|
|
| 7 |
``` cpp
|
| 8 |
partial_sum(istream_iterator<double, char>(cin),
|
| 9 |
istream_iterator<double, char>(),
|
| 10 |
ostream_iterator<double, char>(cout, "\n"));
|
| 11 |
```
|
| 12 |
|
| 13 |
-
reads a file containing floating
|
| 14 |
the partial sums onto `cout`.
|
| 15 |
|
|
|
|
|
|
|
| 16 |
### Class template `istream_iterator` <a id="istream.iterator">[[istream.iterator]]</a>
|
| 17 |
|
| 18 |
The class template `istream_iterator` is an input iterator (
|
| 19 |
[[input.iterators]]) that reads (using `operator>>`) successive elements
|
| 20 |
from the input stream for which it was constructed. After it is
|
|
@@ -27,35 +31,42 @@ object, which is the only legitimate iterator to be used for the end
|
|
| 27 |
condition. The result of `operator*` on an end-of-stream iterator is not
|
| 28 |
defined. For any other iterator value a `const T&` is returned. The
|
| 29 |
result of `operator->` on an end-of-stream iterator is not defined. For
|
| 30 |
any other iterator value a `const T*` is returned. The behavior of a
|
| 31 |
program that applies `operator++()` to an end-of-stream iterator is
|
| 32 |
-
undefined. It is impossible to store things into istream iterators.
|
|
|
|
|
|
|
| 33 |
|
| 34 |
Two end-of-stream iterators are always equal. An end-of-stream iterator
|
| 35 |
is not equal to a non-end-of-stream iterator. Two non-end-of-stream
|
| 36 |
iterators are equal when they are constructed from the same stream.
|
| 37 |
|
| 38 |
``` cpp
|
| 39 |
namespace std {
|
| 40 |
template <class T, class charT = char, class traits = char_traits<charT>,
|
| 41 |
class Distance = ptrdiff_t>
|
| 42 |
-
class istream_iterator
|
| 43 |
-
public iterator<input_iterator_tag, T, Distance, const T*, const T&> {
|
| 44 |
public:
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
istream_iterator(istream_type& s);
|
| 50 |
istream_iterator(const istream_iterator& x) = default;
|
| 51 |
~istream_iterator() = default;
|
| 52 |
|
| 53 |
const T& operator*() const;
|
| 54 |
const T* operator->() const;
|
| 55 |
-
istream_iterator
|
| 56 |
-
istream_iterator
|
| 57 |
private:
|
| 58 |
basic_istream<charT,traits>* in_stream; // exposition only
|
| 59 |
T value; // exposition only
|
| 60 |
};
|
| 61 |
|
|
@@ -69,77 +80,80 @@ namespace std {
|
|
| 69 |
```
|
| 70 |
|
| 71 |
#### `istream_iterator` constructors and destructor <a id="istream.iterator.cons">[[istream.iterator.cons]]</a>
|
| 72 |
|
| 73 |
``` cpp
|
| 74 |
-
|
| 75 |
```
|
| 76 |
|
| 77 |
-
*Effects:* Constructs the end-of-stream iterator. If
|
| 78 |
-
|
|
|
|
| 79 |
|
| 80 |
-
`in_stream == 0`.
|
| 81 |
|
| 82 |
``` cpp
|
| 83 |
istream_iterator(istream_type& s);
|
| 84 |
```
|
| 85 |
|
| 86 |
-
*Effects:* Initializes
|
| 87 |
-
during construction or the first time it is referenced.
|
| 88 |
|
| 89 |
-
`in_stream ==
|
| 90 |
|
| 91 |
``` cpp
|
| 92 |
istream_iterator(const istream_iterator& x) = default;
|
| 93 |
```
|
| 94 |
|
| 95 |
-
*Effects:* Constructs a copy of `x`. If
|
| 96 |
-
|
|
|
|
| 97 |
|
| 98 |
-
`in_stream == x.in_stream`.
|
| 99 |
|
| 100 |
``` cpp
|
| 101 |
~istream_iterator() = default;
|
| 102 |
```
|
| 103 |
|
| 104 |
-
*Effects:* The iterator is destroyed. If
|
| 105 |
-
|
|
|
|
| 106 |
|
| 107 |
#### `istream_iterator` operations <a id="istream.iterator.ops">[[istream.iterator.ops]]</a>
|
| 108 |
|
| 109 |
``` cpp
|
| 110 |
const T& operator*() const;
|
| 111 |
```
|
| 112 |
|
| 113 |
-
*Returns:*
|
| 114 |
|
| 115 |
``` cpp
|
| 116 |
const T* operator->() const;
|
| 117 |
```
|
| 118 |
|
| 119 |
-
*Returns:* `
|
| 120 |
|
| 121 |
``` cpp
|
| 122 |
-
istream_iterator
|
| 123 |
```
|
| 124 |
|
| 125 |
*Requires:* `in_stream != 0`.
|
| 126 |
|
| 127 |
-
*Effects:* `*in_stream >>value`
|
| 128 |
|
| 129 |
*Returns:* `*this`.
|
| 130 |
|
| 131 |
``` cpp
|
| 132 |
-
istream_iterator
|
| 133 |
```
|
| 134 |
|
| 135 |
*Requires:* `in_stream != 0`.
|
| 136 |
|
| 137 |
-
*Effects:*
|
| 138 |
|
| 139 |
``` cpp
|
| 140 |
-
istream_iterator
|
| 141 |
*in_stream >> value;
|
| 142 |
return (tmp);
|
| 143 |
```
|
| 144 |
|
| 145 |
``` cpp
|
|
@@ -177,25 +191,30 @@ while (first != last)
|
|
| 177 |
is defined as:
|
| 178 |
|
| 179 |
``` cpp
|
| 180 |
namespace std {
|
| 181 |
template <class T, class charT = char, class traits = char_traits<charT>>
|
| 182 |
-
class ostream_iterator
|
| 183 |
-
public iterator<output_iterator_tag, void, void, void, void> {
|
| 184 |
public:
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
ostream_iterator(ostream_type& s);
|
| 189 |
ostream_iterator(ostream_type& s, const charT* delimiter);
|
| 190 |
-
ostream_iterator(const ostream_iterator
|
| 191 |
~ostream_iterator();
|
| 192 |
-
ostream_iterator
|
| 193 |
|
| 194 |
-
ostream_iterator
|
| 195 |
-
ostream_iterator
|
| 196 |
-
ostream_iterator
|
| 197 |
private:
|
| 198 |
basic_ostream<charT,traits>* out_stream; // exposition only
|
| 199 |
const charT* delim; // exposition only
|
| 200 |
};
|
| 201 |
}
|
|
@@ -205,17 +224,18 @@ namespace std {
|
|
| 205 |
|
| 206 |
``` cpp
|
| 207 |
ostream_iterator(ostream_type& s);
|
| 208 |
```
|
| 209 |
|
| 210 |
-
*Effects:* Initializes
|
|
|
|
| 211 |
|
| 212 |
``` cpp
|
| 213 |
ostream_iterator(ostream_type& s, const charT* delimiter);
|
| 214 |
```
|
| 215 |
|
| 216 |
-
*Effects:* Initializes
|
| 217 |
`delimiter`.
|
| 218 |
|
| 219 |
``` cpp
|
| 220 |
ostream_iterator(const ostream_iterator& x);
|
| 221 |
```
|
|
@@ -232,11 +252,11 @@ ostream_iterator(const ostream_iterator& x);
|
|
| 232 |
|
| 233 |
``` cpp
|
| 234 |
ostream_iterator& operator=(const T& value);
|
| 235 |
```
|
| 236 |
|
| 237 |
-
*Effects:*
|
| 238 |
|
| 239 |
``` cpp
|
| 240 |
*out_stream << value;
|
| 241 |
if (delim != 0)
|
| 242 |
*out_stream << delim;
|
|
@@ -259,49 +279,50 @@ ostream_iterator& operator++(int);
|
|
| 259 |
### Class template `istreambuf_iterator` <a id="istreambuf.iterator">[[istreambuf.iterator]]</a>
|
| 260 |
|
| 261 |
The class template `istreambuf_iterator` defines an input iterator (
|
| 262 |
[[input.iterators]]) that reads successive *characters* from the
|
| 263 |
streambuf for which it was constructed. `operator*` provides access to
|
| 264 |
-
the current input character, if any. `operator
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
constructor `istreambuf_iterator()`
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
`istreambuf_iterator` shall have a trivial copy constructor, a
|
| 273 |
`constexpr` default constructor, and a trivial destructor.
|
| 274 |
|
| 275 |
The result of `operator*()` on an end-of-stream iterator is undefined.
|
| 276 |
For any other iterator value a `char_type` value is returned. It is
|
| 277 |
impossible to assign a character via an input iterator.
|
| 278 |
|
| 279 |
``` cpp
|
| 280 |
namespace std {
|
| 281 |
template<class charT, class traits = char_traits<charT>>
|
| 282 |
-
class istreambuf_iterator
|
| 283 |
-
: public iterator<input_iterator_tag, charT,
|
| 284 |
-
typename traits::off_type, unspecified, charT> {
|
| 285 |
public:
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
|
| 292 |
class proxy; // exposition only
|
| 293 |
|
| 294 |
constexpr istreambuf_iterator() noexcept;
|
| 295 |
istreambuf_iterator(const istreambuf_iterator&) noexcept = default;
|
| 296 |
~istreambuf_iterator() = default;
|
| 297 |
istreambuf_iterator(istream_type& s) noexcept;
|
| 298 |
istreambuf_iterator(streambuf_type* s) noexcept;
|
| 299 |
istreambuf_iterator(const proxy& p) noexcept;
|
| 300 |
charT operator*() const;
|
| 301 |
-
|
| 302 |
-
istreambuf_iterator<charT,traits>& operator++();
|
| 303 |
proxy operator++(int);
|
| 304 |
bool equal(const istreambuf_iterator& b) const;
|
| 305 |
private:
|
| 306 |
streambuf_type* sbuf_; // exposition only
|
| 307 |
};
|
|
@@ -313,11 +334,11 @@ namespace std {
|
|
| 313 |
bool operator!=(const istreambuf_iterator<charT,traits>& a,
|
| 314 |
const istreambuf_iterator<charT,traits>& b);
|
| 315 |
}
|
| 316 |
```
|
| 317 |
|
| 318 |
-
#### Class template `istreambuf_iterator::proxy` <a id="istreambuf.iterator
|
| 319 |
|
| 320 |
``` cpp
|
| 321 |
namespace std {
|
| 322 |
template <class charT, class traits = char_traits<charT>>
|
| 323 |
class istreambuf_iterator<charT, traits>::proxy { // exposition only
|
|
@@ -339,81 +360,77 @@ placeholder as the return value of the post-increment operator
|
|
| 339 |
(`operator++`). It keeps the character pointed to by the previous value
|
| 340 |
of the iterator for some possible future access to get the character.
|
| 341 |
|
| 342 |
#### `istreambuf_iterator` constructors <a id="istreambuf.iterator.cons">[[istreambuf.iterator.cons]]</a>
|
| 343 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
``` cpp
|
| 345 |
constexpr istreambuf_iterator() noexcept;
|
| 346 |
```
|
| 347 |
|
| 348 |
-
*Effects:*
|
| 349 |
|
| 350 |
``` cpp
|
| 351 |
-
istreambuf_iterator(
|
| 352 |
-
istreambuf_iterator(basic_streambuf<charT,traits>* s) noexcept;
|
| 353 |
```
|
| 354 |
|
| 355 |
-
*Effects:*
|
| 356 |
-
|
| 357 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
|
| 359 |
``` cpp
|
| 360 |
istreambuf_iterator(const proxy& p) noexcept;
|
| 361 |
```
|
| 362 |
|
| 363 |
-
*Effects:*
|
| 364 |
-
`basic_streambuf<>` object pointed to by the `proxy` object’s
|
| 365 |
-
constructor argument `p`.
|
| 366 |
|
| 367 |
-
#### `istreambuf_iterator
|
| 368 |
|
| 369 |
``` cpp
|
| 370 |
charT operator*() const
|
| 371 |
```
|
| 372 |
|
| 373 |
*Returns:* The character obtained via the `streambuf` member
|
| 374 |
`sbuf_->sgetc()`.
|
| 375 |
|
| 376 |
-
#### `istreambuf_iterator::operator++` <a id="istreambuf.iterator::op++">[[istreambuf.iterator::op++]]</a>
|
| 377 |
-
|
| 378 |
``` cpp
|
| 379 |
-
istreambuf_iterator
|
| 380 |
-
istreambuf_iterator<charT,traits>::operator++();
|
| 381 |
```
|
| 382 |
|
| 383 |
-
*Effects:* `sbuf_->sbumpc()`.
|
| 384 |
|
| 385 |
*Returns:* `*this`.
|
| 386 |
|
| 387 |
``` cpp
|
| 388 |
-
proxy
|
| 389 |
```
|
| 390 |
|
| 391 |
*Returns:* `proxy(sbuf_->sbumpc(), sbuf_)`.
|
| 392 |
|
| 393 |
-
#### `istreambuf_iterator::equal` <a id="istreambuf.iterator::equal">[[istreambuf.iterator::equal]]</a>
|
| 394 |
-
|
| 395 |
``` cpp
|
| 396 |
-
bool equal(const istreambuf_iterator
|
| 397 |
```
|
| 398 |
|
| 399 |
*Returns:* `true` if and only if both iterators are at end-of-stream, or
|
| 400 |
neither is at end-of-stream, regardless of what `streambuf` object they
|
| 401 |
use.
|
| 402 |
|
| 403 |
-
#### `operator==` <a id="istreambuf.iterator::op==">[[istreambuf.iterator::op==]]</a>
|
| 404 |
-
|
| 405 |
``` cpp
|
| 406 |
template <class charT, class traits>
|
| 407 |
bool operator==(const istreambuf_iterator<charT,traits>& a,
|
| 408 |
const istreambuf_iterator<charT,traits>& b);
|
| 409 |
```
|
| 410 |
|
| 411 |
*Returns:* `a.equal(b)`.
|
| 412 |
|
| 413 |
-
#### `operator!=` <a id="istreambuf.iterator::op!=">[[istreambuf.iterator::op!=]]</a>
|
| 414 |
-
|
| 415 |
``` cpp
|
| 416 |
template <class charT, class traits>
|
| 417 |
bool operator!=(const istreambuf_iterator<charT,traits>& a,
|
| 418 |
const istreambuf_iterator<charT,traits>& b);
|
| 419 |
```
|
|
@@ -423,19 +440,22 @@ template <class charT, class traits>
|
|
| 423 |
### Class template `ostreambuf_iterator` <a id="ostreambuf.iterator">[[ostreambuf.iterator]]</a>
|
| 424 |
|
| 425 |
``` cpp
|
| 426 |
namespace std {
|
| 427 |
template <class charT, class traits = char_traits<charT>>
|
| 428 |
-
class ostreambuf_iterator
|
| 429 |
-
public iterator<output_iterator_tag, void, void, void, void> {
|
| 430 |
public:
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 435 |
|
| 436 |
-
public:
|
| 437 |
ostreambuf_iterator(ostream_type& s) noexcept;
|
| 438 |
ostreambuf_iterator(streambuf_type* s) noexcept;
|
| 439 |
ostreambuf_iterator& operator=(charT c);
|
| 440 |
|
| 441 |
ostreambuf_iterator& operator*();
|
|
@@ -472,28 +492,27 @@ ostreambuf_iterator(streambuf_type* s) noexcept;
|
|
| 472 |
*Effects:* Initializes `sbuf_` with `s`.
|
| 473 |
|
| 474 |
#### `ostreambuf_iterator` operations <a id="ostreambuf.iter.ops">[[ostreambuf.iter.ops]]</a>
|
| 475 |
|
| 476 |
``` cpp
|
| 477 |
-
ostreambuf_iterator
|
| 478 |
-
operator=(charT c);
|
| 479 |
```
|
| 480 |
|
| 481 |
*Effects:* If `failed()` yields `false`, calls `sbuf_->sputc(c)`;
|
| 482 |
otherwise has no effect.
|
| 483 |
|
| 484 |
*Returns:* `*this`.
|
| 485 |
|
| 486 |
``` cpp
|
| 487 |
-
ostreambuf_iterator
|
| 488 |
```
|
| 489 |
|
| 490 |
*Returns:* `*this`.
|
| 491 |
|
| 492 |
``` cpp
|
| 493 |
-
ostreambuf_iterator
|
| 494 |
-
ostreambuf_iterator
|
| 495 |
```
|
| 496 |
|
| 497 |
*Returns:* `*this`.
|
| 498 |
|
| 499 |
``` cpp
|
|
|
|
| 2 |
|
| 3 |
To make it possible for algorithmic templates to work directly with
|
| 4 |
input/output streams, appropriate iterator-like class templates are
|
| 5 |
provided.
|
| 6 |
|
| 7 |
+
[*Example 1*:
|
| 8 |
+
|
| 9 |
``` cpp
|
| 10 |
partial_sum(istream_iterator<double, char>(cin),
|
| 11 |
istream_iterator<double, char>(),
|
| 12 |
ostream_iterator<double, char>(cout, "\n"));
|
| 13 |
```
|
| 14 |
|
| 15 |
+
reads a file containing floating-point numbers from `cin`, and prints
|
| 16 |
the partial sums onto `cout`.
|
| 17 |
|
| 18 |
+
— *end example*]
|
| 19 |
+
|
| 20 |
### Class template `istream_iterator` <a id="istream.iterator">[[istream.iterator]]</a>
|
| 21 |
|
| 22 |
The class template `istream_iterator` is an input iterator (
|
| 23 |
[[input.iterators]]) that reads (using `operator>>`) successive elements
|
| 24 |
from the input stream for which it was constructed. After it is
|
|
|
|
| 31 |
condition. The result of `operator*` on an end-of-stream iterator is not
|
| 32 |
defined. For any other iterator value a `const T&` is returned. The
|
| 33 |
result of `operator->` on an end-of-stream iterator is not defined. For
|
| 34 |
any other iterator value a `const T*` is returned. The behavior of a
|
| 35 |
program that applies `operator++()` to an end-of-stream iterator is
|
| 36 |
+
undefined. It is impossible to store things into istream iterators. The
|
| 37 |
+
type `T` shall meet the `DefaultConstructible`, `CopyConstructible`, and
|
| 38 |
+
`CopyAssignable` requirements.
|
| 39 |
|
| 40 |
Two end-of-stream iterators are always equal. An end-of-stream iterator
|
| 41 |
is not equal to a non-end-of-stream iterator. Two non-end-of-stream
|
| 42 |
iterators are equal when they are constructed from the same stream.
|
| 43 |
|
| 44 |
``` cpp
|
| 45 |
namespace std {
|
| 46 |
template <class T, class charT = char, class traits = char_traits<charT>,
|
| 47 |
class Distance = ptrdiff_t>
|
| 48 |
+
class istream_iterator {
|
|
|
|
| 49 |
public:
|
| 50 |
+
using iterator_category = input_iterator_tag;
|
| 51 |
+
using value_type = T;
|
| 52 |
+
using difference_type = Distance;
|
| 53 |
+
using pointer = const T*;
|
| 54 |
+
using reference = const T&;
|
| 55 |
+
using char_type = charT;
|
| 56 |
+
using traits_type = traits;
|
| 57 |
+
using istream_type = basic_istream<charT,traits>;
|
| 58 |
+
|
| 59 |
+
constexpr istream_iterator();
|
| 60 |
istream_iterator(istream_type& s);
|
| 61 |
istream_iterator(const istream_iterator& x) = default;
|
| 62 |
~istream_iterator() = default;
|
| 63 |
|
| 64 |
const T& operator*() const;
|
| 65 |
const T* operator->() const;
|
| 66 |
+
istream_iterator& operator++();
|
| 67 |
+
istream_iterator operator++(int);
|
| 68 |
private:
|
| 69 |
basic_istream<charT,traits>* in_stream; // exposition only
|
| 70 |
T value; // exposition only
|
| 71 |
};
|
| 72 |
|
|
|
|
| 80 |
```
|
| 81 |
|
| 82 |
#### `istream_iterator` constructors and destructor <a id="istream.iterator.cons">[[istream.iterator.cons]]</a>
|
| 83 |
|
| 84 |
``` cpp
|
| 85 |
+
constexpr istream_iterator();
|
| 86 |
```
|
| 87 |
|
| 88 |
+
*Effects:* Constructs the end-of-stream iterator. If
|
| 89 |
+
`is_trivially_default_constructible_v<T>` is `true`, then this
|
| 90 |
+
constructor is a constexpr constructor.
|
| 91 |
|
| 92 |
+
*Postconditions:* `in_stream == 0`.
|
| 93 |
|
| 94 |
``` cpp
|
| 95 |
istream_iterator(istream_type& s);
|
| 96 |
```
|
| 97 |
|
| 98 |
+
*Effects:* Initializes `in_stream` with `addressof(s)`. `value` may be
|
| 99 |
+
initialized during construction or the first time it is referenced.
|
| 100 |
|
| 101 |
+
*Postconditions:* `in_stream == addressof(s)`.
|
| 102 |
|
| 103 |
``` cpp
|
| 104 |
istream_iterator(const istream_iterator& x) = default;
|
| 105 |
```
|
| 106 |
|
| 107 |
+
*Effects:* Constructs a copy of `x`. If
|
| 108 |
+
`is_trivially_copy_constructible_v<T>` is `true`, then this constructor
|
| 109 |
+
is a trivial copy constructor.
|
| 110 |
|
| 111 |
+
*Postconditions:* `in_stream == x.in_stream`.
|
| 112 |
|
| 113 |
``` cpp
|
| 114 |
~istream_iterator() = default;
|
| 115 |
```
|
| 116 |
|
| 117 |
+
*Effects:* The iterator is destroyed. If
|
| 118 |
+
`is_trivially_destructible_v<T>` is `true`, then this destructor is a
|
| 119 |
+
trivial destructor.
|
| 120 |
|
| 121 |
#### `istream_iterator` operations <a id="istream.iterator.ops">[[istream.iterator.ops]]</a>
|
| 122 |
|
| 123 |
``` cpp
|
| 124 |
const T& operator*() const;
|
| 125 |
```
|
| 126 |
|
| 127 |
+
*Returns:* `value`.
|
| 128 |
|
| 129 |
``` cpp
|
| 130 |
const T* operator->() const;
|
| 131 |
```
|
| 132 |
|
| 133 |
+
*Returns:* `addressof(operator*())`.
|
| 134 |
|
| 135 |
``` cpp
|
| 136 |
+
istream_iterator& operator++();
|
| 137 |
```
|
| 138 |
|
| 139 |
*Requires:* `in_stream != 0`.
|
| 140 |
|
| 141 |
+
*Effects:* As if by: `*in_stream >> value;`
|
| 142 |
|
| 143 |
*Returns:* `*this`.
|
| 144 |
|
| 145 |
``` cpp
|
| 146 |
+
istream_iterator operator++(int);
|
| 147 |
```
|
| 148 |
|
| 149 |
*Requires:* `in_stream != 0`.
|
| 150 |
|
| 151 |
+
*Effects:* As if by:
|
| 152 |
|
| 153 |
``` cpp
|
| 154 |
+
istream_iterator tmp = *this;
|
| 155 |
*in_stream >> value;
|
| 156 |
return (tmp);
|
| 157 |
```
|
| 158 |
|
| 159 |
``` cpp
|
|
|
|
| 191 |
is defined as:
|
| 192 |
|
| 193 |
``` cpp
|
| 194 |
namespace std {
|
| 195 |
template <class T, class charT = char, class traits = char_traits<charT>>
|
| 196 |
+
class ostream_iterator {
|
|
|
|
| 197 |
public:
|
| 198 |
+
using iterator_category = output_iterator_tag;
|
| 199 |
+
using value_type = void;
|
| 200 |
+
using difference_type = void;
|
| 201 |
+
using pointer = void;
|
| 202 |
+
using reference = void;
|
| 203 |
+
using char_type = charT;
|
| 204 |
+
using traits_type = traits;
|
| 205 |
+
using ostream_type = basic_ostream<charT,traits>;
|
| 206 |
+
|
| 207 |
ostream_iterator(ostream_type& s);
|
| 208 |
ostream_iterator(ostream_type& s, const charT* delimiter);
|
| 209 |
+
ostream_iterator(const ostream_iterator& x);
|
| 210 |
~ostream_iterator();
|
| 211 |
+
ostream_iterator& operator=(const T& value);
|
| 212 |
|
| 213 |
+
ostream_iterator& operator*();
|
| 214 |
+
ostream_iterator& operator++();
|
| 215 |
+
ostream_iterator& operator++(int);
|
| 216 |
private:
|
| 217 |
basic_ostream<charT,traits>* out_stream; // exposition only
|
| 218 |
const charT* delim; // exposition only
|
| 219 |
};
|
| 220 |
}
|
|
|
|
| 224 |
|
| 225 |
``` cpp
|
| 226 |
ostream_iterator(ostream_type& s);
|
| 227 |
```
|
| 228 |
|
| 229 |
+
*Effects:* Initializes `out_stream` with `addressof(s)` and `delim` with
|
| 230 |
+
null.
|
| 231 |
|
| 232 |
``` cpp
|
| 233 |
ostream_iterator(ostream_type& s, const charT* delimiter);
|
| 234 |
```
|
| 235 |
|
| 236 |
+
*Effects:* Initializes `out_stream` with `addressof(s)` and `delim` with
|
| 237 |
`delimiter`.
|
| 238 |
|
| 239 |
``` cpp
|
| 240 |
ostream_iterator(const ostream_iterator& x);
|
| 241 |
```
|
|
|
|
| 252 |
|
| 253 |
``` cpp
|
| 254 |
ostream_iterator& operator=(const T& value);
|
| 255 |
```
|
| 256 |
|
| 257 |
+
*Effects:* As if by:
|
| 258 |
|
| 259 |
``` cpp
|
| 260 |
*out_stream << value;
|
| 261 |
if (delim != 0)
|
| 262 |
*out_stream << delim;
|
|
|
|
| 279 |
### Class template `istreambuf_iterator` <a id="istreambuf.iterator">[[istreambuf.iterator]]</a>
|
| 280 |
|
| 281 |
The class template `istreambuf_iterator` defines an input iterator (
|
| 282 |
[[input.iterators]]) that reads successive *characters* from the
|
| 283 |
streambuf for which it was constructed. `operator*` provides access to
|
| 284 |
+
the current input character, if any. Each time `operator++` is
|
| 285 |
+
evaluated, the iterator advances to the next input character. If the end
|
| 286 |
+
of stream is reached (`streambuf_type::sgetc()` returns
|
| 287 |
+
`traits::eof()`), the iterator becomes equal to the *end-of-stream*
|
| 288 |
+
iterator value. The default constructor `istreambuf_iterator()` and the
|
| 289 |
+
constructor `istreambuf_iterator(0)` both construct an end-of-stream
|
| 290 |
+
iterator object suitable for use as an end-of-range. All specializations
|
| 291 |
+
of `istreambuf_iterator` shall have a trivial copy constructor, a
|
|
|
|
| 292 |
`constexpr` default constructor, and a trivial destructor.
|
| 293 |
|
| 294 |
The result of `operator*()` on an end-of-stream iterator is undefined.
|
| 295 |
For any other iterator value a `char_type` value is returned. It is
|
| 296 |
impossible to assign a character via an input iterator.
|
| 297 |
|
| 298 |
``` cpp
|
| 299 |
namespace std {
|
| 300 |
template<class charT, class traits = char_traits<charT>>
|
| 301 |
+
class istreambuf_iterator {
|
|
|
|
|
|
|
| 302 |
public:
|
| 303 |
+
using iterator_category = input_iterator_tag;
|
| 304 |
+
using value_type = charT;
|
| 305 |
+
using difference_type = typename traits::off_type;
|
| 306 |
+
using pointer = unspecified;
|
| 307 |
+
using reference = charT;
|
| 308 |
+
using char_type = charT;
|
| 309 |
+
using traits_type = traits;
|
| 310 |
+
using int_type = typename traits::int_type;
|
| 311 |
+
using streambuf_type = basic_streambuf<charT,traits>;
|
| 312 |
+
using istream_type = basic_istream<charT,traits>;
|
| 313 |
|
| 314 |
class proxy; // exposition only
|
| 315 |
|
| 316 |
constexpr istreambuf_iterator() noexcept;
|
| 317 |
istreambuf_iterator(const istreambuf_iterator&) noexcept = default;
|
| 318 |
~istreambuf_iterator() = default;
|
| 319 |
istreambuf_iterator(istream_type& s) noexcept;
|
| 320 |
istreambuf_iterator(streambuf_type* s) noexcept;
|
| 321 |
istreambuf_iterator(const proxy& p) noexcept;
|
| 322 |
charT operator*() const;
|
| 323 |
+
istreambuf_iterator& operator++();
|
|
|
|
| 324 |
proxy operator++(int);
|
| 325 |
bool equal(const istreambuf_iterator& b) const;
|
| 326 |
private:
|
| 327 |
streambuf_type* sbuf_; // exposition only
|
| 328 |
};
|
|
|
|
| 334 |
bool operator!=(const istreambuf_iterator<charT,traits>& a,
|
| 335 |
const istreambuf_iterator<charT,traits>& b);
|
| 336 |
}
|
| 337 |
```
|
| 338 |
|
| 339 |
+
#### Class template `istreambuf_iterator::proxy` <a id="istreambuf.iterator.proxy">[[istreambuf.iterator.proxy]]</a>
|
| 340 |
|
| 341 |
``` cpp
|
| 342 |
namespace std {
|
| 343 |
template <class charT, class traits = char_traits<charT>>
|
| 344 |
class istreambuf_iterator<charT, traits>::proxy { // exposition only
|
|
|
|
| 360 |
(`operator++`). It keeps the character pointed to by the previous value
|
| 361 |
of the iterator for some possible future access to get the character.
|
| 362 |
|
| 363 |
#### `istreambuf_iterator` constructors <a id="istreambuf.iterator.cons">[[istreambuf.iterator.cons]]</a>
|
| 364 |
|
| 365 |
+
For each `istreambuf_iterator` constructor in this section, an
|
| 366 |
+
end-of-stream iterator is constructed if and only if the exposition-only
|
| 367 |
+
member `sbuf_` is initialized with a null pointer value.
|
| 368 |
+
|
| 369 |
``` cpp
|
| 370 |
constexpr istreambuf_iterator() noexcept;
|
| 371 |
```
|
| 372 |
|
| 373 |
+
*Effects:* Initializes `sbuf_` with `nullptr`.
|
| 374 |
|
| 375 |
``` cpp
|
| 376 |
+
istreambuf_iterator(istream_type& s) noexcept;
|
|
|
|
| 377 |
```
|
| 378 |
|
| 379 |
+
*Effects:* Initializes `sbuf_` with `s.rdbuf()`.
|
| 380 |
+
|
| 381 |
+
``` cpp
|
| 382 |
+
istreambuf_iterator(streambuf_type* s) noexcept;
|
| 383 |
+
```
|
| 384 |
+
|
| 385 |
+
*Effects:* Initializes `sbuf_` with `s`.
|
| 386 |
|
| 387 |
``` cpp
|
| 388 |
istreambuf_iterator(const proxy& p) noexcept;
|
| 389 |
```
|
| 390 |
|
| 391 |
+
*Effects:* Initializes `sbuf_` with `p.sbuf_`.
|
|
|
|
|
|
|
| 392 |
|
| 393 |
+
#### `istreambuf_iterator` operations <a id="istreambuf.iterator.ops">[[istreambuf.iterator.ops]]</a>
|
| 394 |
|
| 395 |
``` cpp
|
| 396 |
charT operator*() const
|
| 397 |
```
|
| 398 |
|
| 399 |
*Returns:* The character obtained via the `streambuf` member
|
| 400 |
`sbuf_->sgetc()`.
|
| 401 |
|
|
|
|
|
|
|
| 402 |
``` cpp
|
| 403 |
+
istreambuf_iterator& operator++();
|
|
|
|
| 404 |
```
|
| 405 |
|
| 406 |
+
*Effects:* As if by `sbuf_->sbumpc()`.
|
| 407 |
|
| 408 |
*Returns:* `*this`.
|
| 409 |
|
| 410 |
``` cpp
|
| 411 |
+
proxy operator++(int);
|
| 412 |
```
|
| 413 |
|
| 414 |
*Returns:* `proxy(sbuf_->sbumpc(), sbuf_)`.
|
| 415 |
|
|
|
|
|
|
|
| 416 |
``` cpp
|
| 417 |
+
bool equal(const istreambuf_iterator& b) const;
|
| 418 |
```
|
| 419 |
|
| 420 |
*Returns:* `true` if and only if both iterators are at end-of-stream, or
|
| 421 |
neither is at end-of-stream, regardless of what `streambuf` object they
|
| 422 |
use.
|
| 423 |
|
|
|
|
|
|
|
| 424 |
``` cpp
|
| 425 |
template <class charT, class traits>
|
| 426 |
bool operator==(const istreambuf_iterator<charT,traits>& a,
|
| 427 |
const istreambuf_iterator<charT,traits>& b);
|
| 428 |
```
|
| 429 |
|
| 430 |
*Returns:* `a.equal(b)`.
|
| 431 |
|
|
|
|
|
|
|
| 432 |
``` cpp
|
| 433 |
template <class charT, class traits>
|
| 434 |
bool operator!=(const istreambuf_iterator<charT,traits>& a,
|
| 435 |
const istreambuf_iterator<charT,traits>& b);
|
| 436 |
```
|
|
|
|
| 440 |
### Class template `ostreambuf_iterator` <a id="ostreambuf.iterator">[[ostreambuf.iterator]]</a>
|
| 441 |
|
| 442 |
``` cpp
|
| 443 |
namespace std {
|
| 444 |
template <class charT, class traits = char_traits<charT>>
|
| 445 |
+
class ostreambuf_iterator {
|
|
|
|
| 446 |
public:
|
| 447 |
+
using iterator_category = output_iterator_tag;
|
| 448 |
+
using value_type = void;
|
| 449 |
+
using difference_type = void;
|
| 450 |
+
using pointer = void;
|
| 451 |
+
using reference = void;
|
| 452 |
+
using char_type = charT;
|
| 453 |
+
using traits_type = traits;
|
| 454 |
+
using streambuf_type = basic_streambuf<charT,traits>;
|
| 455 |
+
using ostream_type = basic_ostream<charT,traits>;
|
| 456 |
|
|
|
|
| 457 |
ostreambuf_iterator(ostream_type& s) noexcept;
|
| 458 |
ostreambuf_iterator(streambuf_type* s) noexcept;
|
| 459 |
ostreambuf_iterator& operator=(charT c);
|
| 460 |
|
| 461 |
ostreambuf_iterator& operator*();
|
|
|
|
| 492 |
*Effects:* Initializes `sbuf_` with `s`.
|
| 493 |
|
| 494 |
#### `ostreambuf_iterator` operations <a id="ostreambuf.iter.ops">[[ostreambuf.iter.ops]]</a>
|
| 495 |
|
| 496 |
``` cpp
|
| 497 |
+
ostreambuf_iterator& operator=(charT c);
|
|
|
|
| 498 |
```
|
| 499 |
|
| 500 |
*Effects:* If `failed()` yields `false`, calls `sbuf_->sputc(c)`;
|
| 501 |
otherwise has no effect.
|
| 502 |
|
| 503 |
*Returns:* `*this`.
|
| 504 |
|
| 505 |
``` cpp
|
| 506 |
+
ostreambuf_iterator& operator*();
|
| 507 |
```
|
| 508 |
|
| 509 |
*Returns:* `*this`.
|
| 510 |
|
| 511 |
``` cpp
|
| 512 |
+
ostreambuf_iterator& operator++();
|
| 513 |
+
ostreambuf_iterator& operator++(int);
|
| 514 |
```
|
| 515 |
|
| 516 |
*Returns:* `*this`.
|
| 517 |
|
| 518 |
``` cpp
|