From Jason Turner

[range.istream]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpdsrols_j/{from.md → to.md} +23 -32
tmp/tmpdsrols_j/{from.md → to.md} RENAMED
@@ -3,15 +3,25 @@
3
  #### Overview <a id="range.istream.overview">[[range.istream.overview]]</a>
4
 
5
  `basic_istream_view` models `input_range` and reads (using `operator>>`)
6
  successive elements from its corresponding input stream.
7
 
 
 
 
 
 
 
 
 
 
 
8
  [*Example 1*:
9
 
10
  ``` cpp
11
  auto ints = istringstream{"0 1 2 3 4"};
12
- ranges::copy(istream_view<int>(ints), ostream_iterator<int>{cout, "-"});
13
  // prints 0-1-2-3-4-
14
  ```
15
 
16
  — *end example*]
17
 
@@ -23,32 +33,29 @@ namespace std::ranges {
23
  concept stream-extractable = // exposition only
24
  requires(basic_istream<CharT, Traits>& is, Val& t) {
25
  is >> t;
26
  };
27
 
28
- template<movable Val, class CharT, class Traits>
29
  requires default_initializable<Val> &&
30
  stream-extractable<Val, CharT, Traits>
31
  class basic_istream_view : public view_interface<basic_istream_view<Val, CharT, Traits>> {
32
  public:
33
- basic_istream_view() = default;
34
  constexpr explicit basic_istream_view(basic_istream<CharT, Traits>& stream);
35
 
36
- constexpr auto begin()
37
- {
38
- if (stream_) {
39
- *stream_ >> object_;
40
- }
41
  return iterator{*this};
42
  }
43
 
44
  constexpr default_sentinel_t end() const noexcept;
45
 
46
  private:
 
47
  struct iterator; // exposition only
48
- basic_istream<CharT, Traits>* stream_ = nullptr; // exposition only
49
- Val object_ = Val(); // exposition only
50
  };
51
  }
52
  ```
53
 
54
  ``` cpp
@@ -61,32 +68,23 @@ constexpr explicit basic_istream_view(basic_istream<CharT, Traits>& stream);
61
  constexpr default_sentinel_t end() const noexcept;
62
  ```
63
 
64
  *Effects:* Equivalent to: `return default_sentinel;`
65
 
66
- ``` cpp
67
- template<class Val, class CharT, class Traits>
68
- basic_istream_view<Val, CharT, Traits> istream_view(basic_istream<CharT, Traits>& s);
69
- ```
70
-
71
- *Effects:* Equivalent to:
72
- `return basic_istream_view<Val, CharT, Traits>{s};`
73
-
74
- #### Class template `basic_istream_view::iterator` <a id="range.istream.iterator">[[range.istream.iterator]]</a>
75
 
76
  ``` cpp
77
  namespace std::ranges {
78
  template<movable Val, class CharT, class Traits>
79
  requires default_initializable<Val> &&
80
  stream-extractable<Val, CharT, Traits>
81
- class basic_istream_view<Val, CharT, Traits>::iterator { // exposition only
82
  public:
83
  using iterator_concept = input_iterator_tag;
84
  using difference_type = ptrdiff_t;
85
  using value_type = Val;
86
 
87
- iterator() = default;
88
  constexpr explicit iterator(basic_istream_view& parent) noexcept;
89
 
90
  iterator(const iterator&) = delete;
91
  iterator(iterator&&) = default;
92
 
@@ -99,11 +97,11 @@ namespace std::ranges {
99
  Val& operator*() const;
100
 
101
  friend bool operator==(const iterator& x, default_sentinel_t);
102
 
103
  private:
104
- basic_istream_view* parent_ = nullptr; // exposition only
105
  };
106
  }
107
  ```
108
 
109
  ``` cpp
@@ -114,37 +112,30 @@ constexpr explicit iterator(basic_istream_view& parent) noexcept;
114
 
115
  ``` cpp
116
  iterator& operator++();
117
  ```
118
 
119
- *Preconditions:* *`parent_`*`->`*`stream_`*` != nullptr` is `true`.
120
-
121
  *Effects:* Equivalent to:
122
 
123
  ``` cpp
124
- *parent_->stream_>> parent_->object_;
125
  return *this;
126
  ```
127
 
128
  ``` cpp
129
  void operator++(int);
130
  ```
131
 
132
- *Preconditions:* *`parent_`*`->`*`stream_`*` != nullptr` is `true`.
133
-
134
  *Effects:* Equivalent to `++*this`.
135
 
136
  ``` cpp
137
  Val& operator*() const;
138
  ```
139
 
140
- *Preconditions:* *`parent_`*`->`*`stream_`*` != nullptr` is `true`.
141
-
142
- *Effects:* Equivalent to: `return `*`parent_`*`->`*`object_`*`;`
143
 
144
  ``` cpp
145
  friend bool operator==(const iterator& x, default_sentinel_t);
146
  ```
147
 
148
- *Effects:* Equivalent to:
149
- `return x.`*`parent_`*` == nullptr || !*x.`*`parent_`*`->`*`stream_`*`;`
150
 
 
3
  #### Overview <a id="range.istream.overview">[[range.istream.overview]]</a>
4
 
5
  `basic_istream_view` models `input_range` and reads (using `operator>>`)
6
  successive elements from its corresponding input stream.
7
 
8
+ The name `views::istream<T>` denotes a customization point object
9
+ [[customization.point.object]]. Given a type `T` and a subexpression `E`
10
+ of type `U`, if `U` models
11
+ `derived_from<basic_istream<typename U::char_type,
12
+ typename U::traits_type>>`, then the expression `views::istream<T>(E)`
13
+ is expression-equivalent to
14
+ `basic_istream_view<T, typename U::char_type,
15
+ typename U::traits_type>(E)`; otherwise, `views::istream<T>(E)` is
16
+ ill-formed.
17
+
18
  [*Example 1*:
19
 
20
  ``` cpp
21
  auto ints = istringstream{"0 1 2 3 4"};
22
+ ranges::copy(views::istream<int>(ints), ostream_iterator<int>{cout, "-"});
23
  // prints 0-1-2-3-4-
24
  ```
25
 
26
  — *end example*]
27
 
 
33
  concept stream-extractable = // exposition only
34
  requires(basic_istream<CharT, Traits>& is, Val& t) {
35
  is >> t;
36
  };
37
 
38
+ template<movable Val, class CharT, class Traits = char_traits<CharT>>
39
  requires default_initializable<Val> &&
40
  stream-extractable<Val, CharT, Traits>
41
  class basic_istream_view : public view_interface<basic_istream_view<Val, CharT, Traits>> {
42
  public:
 
43
  constexpr explicit basic_istream_view(basic_istream<CharT, Traits>& stream);
44
 
45
+ constexpr auto begin() {
46
+ *stream_ >> value_;
 
 
 
47
  return iterator{*this};
48
  }
49
 
50
  constexpr default_sentinel_t end() const noexcept;
51
 
52
  private:
53
+ // [range.istream.iterator], class basic_istream_view::iterator
54
  struct iterator; // exposition only
55
+ basic_istream<CharT, Traits>* stream_; // exposition only
56
+ Val value_ = Val(); // exposition only
57
  };
58
  }
59
  ```
60
 
61
  ``` cpp
 
68
  constexpr default_sentinel_t end() const noexcept;
69
  ```
70
 
71
  *Effects:* Equivalent to: `return default_sentinel;`
72
 
73
+ #### Class `basic_istream_view::iterator` <a id="range.istream.iterator">[[range.istream.iterator]]</a>
 
 
 
 
 
 
 
 
74
 
75
  ``` cpp
76
  namespace std::ranges {
77
  template<movable Val, class CharT, class Traits>
78
  requires default_initializable<Val> &&
79
  stream-extractable<Val, CharT, Traits>
80
+ class basic_istream_view<Val, CharT, Traits>::iterator {
81
  public:
82
  using iterator_concept = input_iterator_tag;
83
  using difference_type = ptrdiff_t;
84
  using value_type = Val;
85
 
 
86
  constexpr explicit iterator(basic_istream_view& parent) noexcept;
87
 
88
  iterator(const iterator&) = delete;
89
  iterator(iterator&&) = default;
90
 
 
97
  Val& operator*() const;
98
 
99
  friend bool operator==(const iterator& x, default_sentinel_t);
100
 
101
  private:
102
+ basic_istream_view* parent_; // exposition only
103
  };
104
  }
105
  ```
106
 
107
  ``` cpp
 
112
 
113
  ``` cpp
114
  iterator& operator++();
115
  ```
116
 
 
 
117
  *Effects:* Equivalent to:
118
 
119
  ``` cpp
120
+ *parent_->stream_ >> parent_->value_;
121
  return *this;
122
  ```
123
 
124
  ``` cpp
125
  void operator++(int);
126
  ```
127
 
 
 
128
  *Effects:* Equivalent to `++*this`.
129
 
130
  ``` cpp
131
  Val& operator*() const;
132
  ```
133
 
134
+ *Effects:* Equivalent to: `return `*`parent_`*`->`*`value_`*`;`
 
 
135
 
136
  ``` cpp
137
  friend bool operator==(const iterator& x, default_sentinel_t);
138
  ```
139
 
140
+ *Effects:* Equivalent to: `return !*x.`*`parent_`*`->`*`stream_`*`;`
 
141