tmp/tmpbmpacg0m/{from.md → to.md}
RENAMED
|
@@ -1,28 +1,10 @@
|
|
| 1 |
### Class template `istream_iterator` <a id="istream.iterator">[[istream.iterator]]</a>
|
| 2 |
|
| 3 |
-
The class template `istream_iterator` is an input iterator
|
| 4 |
-
[[input.iterators]]
|
| 5 |
-
|
| 6 |
-
constructed, and every time `++` is used, the iterator reads and stores
|
| 7 |
-
a value of `T`. If the iterator fails to read and store a value of `T`
|
| 8 |
-
(`fail()` on the stream returns `true`), the iterator becomes equal to
|
| 9 |
-
the *end-of-stream* iterator value. The constructor with no arguments
|
| 10 |
-
`istream_iterator()` always constructs an end-of-stream input iterator
|
| 11 |
-
object, which is the only legitimate iterator to be used for the end
|
| 12 |
-
condition. The result of `operator*` on an end-of-stream iterator is not
|
| 13 |
-
defined. For any other iterator value a `const T&` is returned. The
|
| 14 |
-
result of `operator->` on an end-of-stream iterator is not defined. For
|
| 15 |
-
any other iterator value a `const T*` is returned. The behavior of a
|
| 16 |
-
program that applies `operator++()` to an end-of-stream iterator is
|
| 17 |
-
undefined. It is impossible to store things into istream iterators. The
|
| 18 |
-
type `T` shall meet the `DefaultConstructible`, `CopyConstructible`, and
|
| 19 |
-
`CopyAssignable` requirements.
|
| 20 |
-
|
| 21 |
-
Two end-of-stream iterators are always equal. An end-of-stream iterator
|
| 22 |
-
is not equal to a non-end-of-stream iterator. Two non-end-of-stream
|
| 23 |
-
iterators are equal when they are constructed from the same stream.
|
| 24 |
|
| 25 |
``` cpp
|
| 26 |
namespace std {
|
| 27 |
template<class T, class charT = char, class traits = char_traits<charT>,
|
| 28 |
class Distance = ptrdiff_t>
|
|
@@ -36,107 +18,117 @@ namespace std {
|
|
| 36 |
using char_type = charT;
|
| 37 |
using traits_type = traits;
|
| 38 |
using istream_type = basic_istream<charT,traits>;
|
| 39 |
|
| 40 |
constexpr istream_iterator();
|
|
|
|
| 41 |
istream_iterator(istream_type& s);
|
| 42 |
istream_iterator(const istream_iterator& x) = default;
|
| 43 |
~istream_iterator() = default;
|
|
|
|
| 44 |
|
| 45 |
const T& operator*() const;
|
| 46 |
const T* operator->() const;
|
| 47 |
istream_iterator& operator++();
|
| 48 |
istream_iterator operator++(int);
|
|
|
|
|
|
|
|
|
|
| 49 |
private:
|
| 50 |
basic_istream<charT,traits>* in_stream; // exposition only
|
| 51 |
T value; // exposition only
|
| 52 |
};
|
| 53 |
-
|
| 54 |
-
template <class T, class charT, class traits, class Distance>
|
| 55 |
-
bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
|
| 56 |
-
const istream_iterator<T,charT,traits,Distance>& y);
|
| 57 |
-
template <class T, class charT, class traits, class Distance>
|
| 58 |
-
bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
|
| 59 |
-
const istream_iterator<T,charT,traits,Distance>& y);
|
| 60 |
}
|
| 61 |
```
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
``` cpp
|
| 66 |
constexpr istream_iterator();
|
|
|
|
| 67 |
```
|
| 68 |
|
| 69 |
-
*Effects:* Constructs the end-of-stream iterator
|
| 70 |
-
`
|
| 71 |
-
constructor is a constexpr constructor.
|
| 72 |
|
| 73 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
``` cpp
|
| 76 |
istream_iterator(istream_type& s);
|
| 77 |
```
|
| 78 |
|
| 79 |
-
*Effects:* Initializes `in_stream` with `addressof(s)`
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
*Postconditions:* `in_stream == addressof(s)`.
|
| 83 |
|
| 84 |
``` cpp
|
| 85 |
istream_iterator(const istream_iterator& x) = default;
|
| 86 |
```
|
| 87 |
|
| 88 |
-
*
|
| 89 |
-
`is_trivially_copy_constructible_v<T>` is `true`, then this constructor
|
| 90 |
-
is a trivial copy constructor.
|
| 91 |
|
| 92 |
-
*
|
|
|
|
| 93 |
|
| 94 |
``` cpp
|
| 95 |
~istream_iterator() = default;
|
| 96 |
```
|
| 97 |
|
| 98 |
-
*
|
| 99 |
-
|
| 100 |
-
trivial destructor.
|
| 101 |
|
| 102 |
-
####
|
| 103 |
|
| 104 |
``` cpp
|
| 105 |
const T& operator*() const;
|
| 106 |
```
|
| 107 |
|
|
|
|
|
|
|
| 108 |
*Returns:* `value`.
|
| 109 |
|
| 110 |
``` cpp
|
| 111 |
const T* operator->() const;
|
| 112 |
```
|
| 113 |
|
| 114 |
-
*
|
|
|
|
|
|
|
| 115 |
|
| 116 |
``` cpp
|
| 117 |
istream_iterator& operator++();
|
| 118 |
```
|
| 119 |
|
| 120 |
-
*
|
| 121 |
|
| 122 |
-
*Effects:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
*Returns:* `*this`.
|
| 125 |
|
| 126 |
``` cpp
|
| 127 |
istream_iterator operator++(int);
|
| 128 |
```
|
| 129 |
|
| 130 |
-
*
|
| 131 |
|
| 132 |
-
*Effects:*
|
| 133 |
|
| 134 |
``` cpp
|
| 135 |
istream_iterator tmp = *this;
|
| 136 |
-
*
|
| 137 |
-
return
|
| 138 |
```
|
| 139 |
|
| 140 |
``` cpp
|
| 141 |
template<class T, class charT, class traits, class Distance>
|
| 142 |
bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
|
|
@@ -144,12 +136,10 @@ template <class T, class charT, class traits, class Distance>
|
|
| 144 |
```
|
| 145 |
|
| 146 |
*Returns:* `x.in_stream == y.in_stream`.
|
| 147 |
|
| 148 |
``` cpp
|
| 149 |
-
|
| 150 |
-
bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
|
| 151 |
-
const istream_iterator<T,charT,traits,Distance>& y);
|
| 152 |
```
|
| 153 |
|
| 154 |
-
*Returns:* `!
|
| 155 |
|
|
|
|
| 1 |
### Class template `istream_iterator` <a id="istream.iterator">[[istream.iterator]]</a>
|
| 2 |
|
| 3 |
+
The class template `istream_iterator` is an input iterator
|
| 4 |
+
[[input.iterators]] that reads successive elements from the input stream
|
| 5 |
+
for which it was constructed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
``` cpp
|
| 8 |
namespace std {
|
| 9 |
template<class T, class charT = char, class traits = char_traits<charT>,
|
| 10 |
class Distance = ptrdiff_t>
|
|
|
|
| 18 |
using char_type = charT;
|
| 19 |
using traits_type = traits;
|
| 20 |
using istream_type = basic_istream<charT,traits>;
|
| 21 |
|
| 22 |
constexpr istream_iterator();
|
| 23 |
+
constexpr istream_iterator(default_sentinel_t);
|
| 24 |
istream_iterator(istream_type& s);
|
| 25 |
istream_iterator(const istream_iterator& x) = default;
|
| 26 |
~istream_iterator() = default;
|
| 27 |
+
istream_iterator& operator=(const istream_iterator&) = default;
|
| 28 |
|
| 29 |
const T& operator*() const;
|
| 30 |
const T* operator->() const;
|
| 31 |
istream_iterator& operator++();
|
| 32 |
istream_iterator operator++(int);
|
| 33 |
+
|
| 34 |
+
friend bool operator==(const istream_iterator& i, default_sentinel_t);
|
| 35 |
+
|
| 36 |
private:
|
| 37 |
basic_istream<charT,traits>* in_stream; // exposition only
|
| 38 |
T value; // exposition only
|
| 39 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
}
|
| 41 |
```
|
| 42 |
|
| 43 |
+
The type `T` shall meet the *Cpp17DefaultConstructible*,
|
| 44 |
+
*Cpp17CopyConstructible*, and *Cpp17CopyAssignable* requirements.
|
| 45 |
+
|
| 46 |
+
#### Constructors and destructor <a id="istream.iterator.cons">[[istream.iterator.cons]]</a>
|
| 47 |
|
| 48 |
``` cpp
|
| 49 |
constexpr istream_iterator();
|
| 50 |
+
constexpr istream_iterator(default_sentinel_t);
|
| 51 |
```
|
| 52 |
|
| 53 |
+
*Effects:* Constructs the end-of-stream iterator, value-initializing
|
| 54 |
+
`value`.
|
|
|
|
| 55 |
|
| 56 |
+
*Ensures:* `in_stream == nullptr` is `true`.
|
| 57 |
+
|
| 58 |
+
*Remarks:* If the initializer `T()` in the declaration `auto x = T();`
|
| 59 |
+
is a constant initializer [[expr.const]], then these constructors are
|
| 60 |
+
`constexpr` constructors.
|
| 61 |
|
| 62 |
``` cpp
|
| 63 |
istream_iterator(istream_type& s);
|
| 64 |
```
|
| 65 |
|
| 66 |
+
*Effects:* Initializes `in_stream` with `addressof(s)`,
|
| 67 |
+
value-initializes `value`, and then calls `operator++()`.
|
|
|
|
|
|
|
| 68 |
|
| 69 |
``` cpp
|
| 70 |
istream_iterator(const istream_iterator& x) = default;
|
| 71 |
```
|
| 72 |
|
| 73 |
+
*Ensures:* `in_stream == x.in_stream` is `true`.
|
|
|
|
|
|
|
| 74 |
|
| 75 |
+
*Remarks:* If `is_trivially_copy_constructible_v<T>` is `true`, then
|
| 76 |
+
this constructor is trivial.
|
| 77 |
|
| 78 |
``` cpp
|
| 79 |
~istream_iterator() = default;
|
| 80 |
```
|
| 81 |
|
| 82 |
+
*Remarks:* If `is_trivially_destructible_v<T>` is `true`, then this
|
| 83 |
+
destructor is trivial.
|
|
|
|
| 84 |
|
| 85 |
+
#### Operations <a id="istream.iterator.ops">[[istream.iterator.ops]]</a>
|
| 86 |
|
| 87 |
``` cpp
|
| 88 |
const T& operator*() const;
|
| 89 |
```
|
| 90 |
|
| 91 |
+
*Preconditions:* `in_stream != nullptr` is `true`.
|
| 92 |
+
|
| 93 |
*Returns:* `value`.
|
| 94 |
|
| 95 |
``` cpp
|
| 96 |
const T* operator->() const;
|
| 97 |
```
|
| 98 |
|
| 99 |
+
*Preconditions:* `in_stream != nullptr` is `true`.
|
| 100 |
+
|
| 101 |
+
*Returns:* `addressof(value)`.
|
| 102 |
|
| 103 |
``` cpp
|
| 104 |
istream_iterator& operator++();
|
| 105 |
```
|
| 106 |
|
| 107 |
+
*Preconditions:* `in_stream != nullptr` is `true`.
|
| 108 |
|
| 109 |
+
*Effects:* Equivalent to:
|
| 110 |
+
|
| 111 |
+
``` cpp
|
| 112 |
+
if (!(*in_stream >> value))
|
| 113 |
+
in_stream = nullptr;
|
| 114 |
+
```
|
| 115 |
|
| 116 |
*Returns:* `*this`.
|
| 117 |
|
| 118 |
``` cpp
|
| 119 |
istream_iterator operator++(int);
|
| 120 |
```
|
| 121 |
|
| 122 |
+
*Preconditions:* `in_stream != nullptr` is `true`.
|
| 123 |
|
| 124 |
+
*Effects:* Equivalent to:
|
| 125 |
|
| 126 |
``` cpp
|
| 127 |
istream_iterator tmp = *this;
|
| 128 |
+
++*this;
|
| 129 |
+
return tmp;
|
| 130 |
```
|
| 131 |
|
| 132 |
``` cpp
|
| 133 |
template<class T, class charT, class traits, class Distance>
|
| 134 |
bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
|
|
|
|
| 136 |
```
|
| 137 |
|
| 138 |
*Returns:* `x.in_stream == y.in_stream`.
|
| 139 |
|
| 140 |
``` cpp
|
| 141 |
+
friend bool operator==(const istream_iterator& i, default_sentinel_t);
|
|
|
|
|
|
|
| 142 |
```
|
| 143 |
|
| 144 |
+
*Returns:* `!i.in_stream`.
|
| 145 |
|