From Jason Turner

[move.iterators]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpd_lazu3y/{from.md → to.md} +79 -69
tmp/tmpd_lazu3y/{from.md → to.md} RENAMED
@@ -1,315 +1,325 @@
1
  ### Move iterators <a id="move.iterators">[[move.iterators]]</a>
2
 
3
  Class template `move_iterator` is an iterator adaptor with the same
4
  behavior as the underlying iterator except that its indirection operator
5
  implicitly converts the value returned by the underlying iterator’s
6
- indirection operator to an rvalue reference. Some generic algorithms can
7
- be called with move iterators to replace copying with moving.
 
 
8
 
9
  ``` cpp
10
  list<string> s;
11
  // populate the list s
12
  vector<string> v1(s.begin(), s.end()); // copies strings into v1
13
  vector<string> v2(make_move_iterator(s.begin()),
14
  make_move_iterator(s.end())); // moves strings into v2
15
  ```
16
 
 
 
17
  #### Class template `move_iterator` <a id="move.iterator">[[move.iterator]]</a>
18
 
19
  ``` cpp
20
  namespace std {
21
  template <class Iterator>
22
  class move_iterator {
23
  public:
24
- typedef Iterator iterator_type;
25
- typedef typename iterator_traits<Iterator>::difference_type difference_type;
26
- typedef Iterator pointer;
27
- typedef typename iterator_traits<Iterator>::value_type value_type;
28
- typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
29
- typedef value_type&& reference;
30
 
31
- move_iterator();
32
- explicit move_iterator(Iterator i);
33
- template <class U> move_iterator(const move_iterator<U>& u);
34
- template <class U> move_iterator& operator=(const move_iterator<U>& u);
35
 
36
- iterator_type base() const;
37
- reference operator*() const;
38
- pointer operator->() const;
39
 
40
- move_iterator& operator++();
41
- move_iterator operator++(int);
42
- move_iterator& operator--();
43
- move_iterator operator--(int);
44
 
45
- move_iterator operator+(difference_type n) const;
46
- move_iterator& operator+=(difference_type n);
47
- move_iterator operator-(difference_type n) const;
48
- move_iterator& operator-=(difference_type n);
49
- unspecified operator[](difference_type n) const;
50
 
51
  private:
52
  Iterator current; // exposition only
53
  };
54
 
55
  template <class Iterator1, class Iterator2>
56
- bool operator==(
57
  const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
58
  template <class Iterator1, class Iterator2>
59
- bool operator!=(
60
  const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
61
  template <class Iterator1, class Iterator2>
62
- bool operator<(
63
  const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
64
  template <class Iterator1, class Iterator2>
65
- bool operator<=(
66
  const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
67
  template <class Iterator1, class Iterator2>
68
- bool operator>(
69
  const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
70
  template <class Iterator1, class Iterator2>
71
- bool operator>=(
72
  const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
73
 
74
  template <class Iterator1, class Iterator2>
75
- auto operator-(
76
  const move_iterator<Iterator1>& x,
77
  const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
78
  template <class Iterator>
79
- move_iterator<Iterator> operator+(
80
  typename move_iterator<Iterator>::difference_type n, const move_iterator<Iterator>& x);
81
  template <class Iterator>
82
- move_iterator<Iterator> make_move_iterator(Iterator i);
83
  }
84
  ```
85
 
 
 
 
 
 
 
86
  #### `move_iterator` requirements <a id="move.iter.requirements">[[move.iter.requirements]]</a>
87
 
88
- The template parameter `Iterator` shall meet the requirements for an
89
- Input Iterator ([[input.iterators]]). Additionally, if any of the
90
  bidirectional or random access traversal functions are instantiated, the
91
  template parameter shall meet the requirements for a Bidirectional
92
  Iterator ([[bidirectional.iterators]]) or a Random Access Iterator (
93
  [[random.access.iterators]]), respectively.
94
 
95
  #### `move_iterator` operations <a id="move.iter.ops">[[move.iter.ops]]</a>
96
 
97
  ##### `move_iterator` constructors <a id="move.iter.op.const">[[move.iter.op.const]]</a>
98
 
99
  ``` cpp
100
- move_iterator();
101
  ```
102
 
103
- *Effects:* Constructs a `move_iterator`, value initializing `current`.
104
  Iterator operations applied to the resulting iterator have defined
105
  behavior if and only if the corresponding operations are defined on a
106
  value-initialized iterator of type `Iterator`.
107
 
108
  ``` cpp
109
- explicit move_iterator(Iterator i);
110
  ```
111
 
112
  *Effects:* Constructs a `move_iterator`, initializing `current` with
113
  `i`.
114
 
115
  ``` cpp
116
- template <class U> move_iterator(const move_iterator<U>& u);
117
  ```
118
 
119
  *Effects:* Constructs a `move_iterator`, initializing `current` with
120
  `u.base()`.
121
 
122
  *Requires:* `U` shall be convertible to `Iterator`.
123
 
124
  ##### `move_iterator::operator=` <a id="move.iter.op=">[[move.iter.op=]]</a>
125
 
126
  ``` cpp
127
- template <class U> move_iterator& operator=(const move_iterator<U>& u);
128
  ```
129
 
130
  *Effects:* Assigns `u.base()` to `current`.
131
 
132
  *Requires:* `U` shall be convertible to `Iterator`.
133
 
134
  ##### `move_iterator` conversion <a id="move.iter.op.conv">[[move.iter.op.conv]]</a>
135
 
136
  ``` cpp
137
- Iterator base() const;
138
  ```
139
 
140
  *Returns:* `current`.
141
 
142
  ##### `move_iterator::operator*` <a id="move.iter.op.star">[[move.iter.op.star]]</a>
143
 
144
  ``` cpp
145
- reference operator*() const;
146
  ```
147
 
148
- *Returns:* `std::move(`\*current).
149
 
150
  ##### `move_iterator::operator->` <a id="move.iter.op.ref">[[move.iter.op.ref]]</a>
151
 
152
  ``` cpp
153
- pointer operator->() const;
154
  ```
155
 
156
  *Returns:* `current`.
157
 
158
  ##### `move_iterator::operator++` <a id="move.iter.op.incr">[[move.iter.op.incr]]</a>
159
 
160
  ``` cpp
161
- move_iterator& operator++();
162
  ```
163
 
164
- *Effects:* `++current`.
165
 
166
  *Returns:* `*this`.
167
 
168
  ``` cpp
169
- move_iterator operator++(int);
170
  ```
171
 
172
- *Effects:*
173
 
174
  ``` cpp
175
  move_iterator tmp = *this;
176
  ++current;
177
  return tmp;
178
  ```
179
 
180
  ##### `move_iterator::operator-{-}` <a id="move.iter.op.decr">[[move.iter.op.decr]]</a>
181
 
182
  ``` cpp
183
- move_iterator& operator--();
184
  ```
185
 
186
- *Effects:* \dcr`current`.
187
 
188
  *Returns:* `*this`.
189
 
190
  ``` cpp
191
- move_iterator operator--(int);
192
  ```
193
 
194
- *Effects:*
195
 
196
  ``` cpp
197
  move_iterator tmp = *this;
198
  --current;
199
  return tmp;
200
  ```
201
 
202
  ##### `move_iterator::operator+` <a id="move.iter.op.+">[[move.iter.op.+]]</a>
203
 
204
  ``` cpp
205
- move_iterator operator+(difference_type n) const;
206
  ```
207
 
208
  *Returns:* `move_iterator(current + n)`.
209
 
210
  ##### `move_iterator::operator+=` <a id="move.iter.op.+=">[[move.iter.op.+=]]</a>
211
 
212
  ``` cpp
213
- move_iterator& operator+=(difference_type n);
214
  ```
215
 
216
- *Effects:* `current += n`.
217
 
218
  *Returns:* `*this`.
219
 
220
  ##### `move_iterator::operator-` <a id="move.iter.op.-">[[move.iter.op.-]]</a>
221
 
222
  ``` cpp
223
- move_iterator operator-(difference_type n) const;
224
  ```
225
 
226
  *Returns:* `move_iterator(current - n)`.
227
 
228
  ##### `move_iterator::operator-=` <a id="move.iter.op.-=">[[move.iter.op.-=]]</a>
229
 
230
  ``` cpp
231
- move_iterator& operator-=(difference_type n);
232
  ```
233
 
234
- *Effects:* `current -= n`.
235
 
236
  *Returns:* `*this`.
237
 
238
  ##### `move_iterator::operator[]` <a id="move.iter.op.index">[[move.iter.op.index]]</a>
239
 
240
  ``` cpp
241
- unspecified operator[](difference_type n) const;
242
  ```
243
 
244
- *Returns:* `std::move(`current\[n\]).
245
 
246
  ##### `move_iterator` comparisons <a id="move.iter.op.comp">[[move.iter.op.comp]]</a>
247
 
248
  ``` cpp
249
  template <class Iterator1, class Iterator2>
250
- bool operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
251
  ```
252
 
253
  *Returns:* `x.base() == y.base()`.
254
 
255
  ``` cpp
256
  template <class Iterator1, class Iterator2>
257
- bool operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
258
  ```
259
 
260
  *Returns:* `!(x == y)`.
261
 
262
  ``` cpp
263
  template <class Iterator1, class Iterator2>
264
- bool operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
265
  ```
266
 
267
  *Returns:* `x.base() < y.base()`.
268
 
269
  ``` cpp
270
  template <class Iterator1, class Iterator2>
271
- bool operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
272
  ```
273
 
274
  *Returns:* `!(y < x)`.
275
 
276
  ``` cpp
277
  template <class Iterator1, class Iterator2>
278
- bool operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
279
  ```
280
 
281
  *Returns:* `y < x`.
282
 
283
  ``` cpp
284
  template <class Iterator1, class Iterator2>
285
- bool operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
286
  ```
287
 
288
  *Returns:* `!(x < y)`.
289
 
290
  ##### `move_iterator` non-member functions <a id="move.iter.nonmember">[[move.iter.nonmember]]</a>
291
 
292
  ``` cpp
293
  template <class Iterator1, class Iterator2>
294
- auto operator-(
295
  const move_iterator<Iterator1>& x,
296
  const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
297
  ```
298
 
299
  *Returns:* `x.base() - y.base()`.
300
 
301
  ``` cpp
302
  template <class Iterator>
303
- move_iterator<Iterator> operator+(
304
  typename move_iterator<Iterator>::difference_type n, const move_iterator<Iterator>& x);
305
  ```
306
 
307
  *Returns:* `x + n`.
308
 
309
  ``` cpp
310
  template <class Iterator>
311
- move_iterator<Iterator> make_move_iterator(Iterator i);
312
  ```
313
 
314
  *Returns:* `move_iterator<Iterator>(i)`.
315
 
 
1
  ### Move iterators <a id="move.iterators">[[move.iterators]]</a>
2
 
3
  Class template `move_iterator` is an iterator adaptor with the same
4
  behavior as the underlying iterator except that its indirection operator
5
  implicitly converts the value returned by the underlying iterator’s
6
+ indirection operator to an rvalue. Some generic algorithms can be called
7
+ with move iterators to replace copying with moving.
8
+
9
+ [*Example 1*:
10
 
11
  ``` cpp
12
  list<string> s;
13
  // populate the list s
14
  vector<string> v1(s.begin(), s.end()); // copies strings into v1
15
  vector<string> v2(make_move_iterator(s.begin()),
16
  make_move_iterator(s.end())); // moves strings into v2
17
  ```
18
 
19
+ — *end example*]
20
+
21
  #### Class template `move_iterator` <a id="move.iterator">[[move.iterator]]</a>
22
 
23
  ``` cpp
24
  namespace std {
25
  template <class Iterator>
26
  class move_iterator {
27
  public:
28
+ using iterator_type = Iterator;
29
+ using iterator_category = typename iterator_traits<Iterator>::iterator_category;
30
+ using value_type = typename iterator_traits<Iterator>::value_type;
31
+ using difference_type = typename iterator_traits<Iterator>::difference_type;
32
+ using pointer = Iterator;
33
+ using reference = see below;
34
 
35
+ constexpr move_iterator();
36
+ constexpr explicit move_iterator(Iterator i);
37
+ template <class U> constexpr move_iterator(const move_iterator<U>& u);
38
+ template <class U> constexpr move_iterator& operator=(const move_iterator<U>& u);
39
 
40
+ constexpr iterator_type base() const;
41
+ constexpr reference operator*() const;
42
+ constexpr pointer operator->() const;
43
 
44
+ constexpr move_iterator& operator++();
45
+ constexpr move_iterator operator++(int);
46
+ constexpr move_iterator& operator--();
47
+ constexpr move_iterator operator--(int);
48
 
49
+ constexpr move_iterator operator+(difference_type n) const;
50
+ constexpr move_iterator& operator+=(difference_type n);
51
+ constexpr move_iterator operator-(difference_type n) const;
52
+ constexpr move_iterator& operator-=(difference_type n);
53
+ constexpr unspecified operator[](difference_type n) const;
54
 
55
  private:
56
  Iterator current; // exposition only
57
  };
58
 
59
  template <class Iterator1, class Iterator2>
60
+ constexpr bool operator==(
61
  const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
62
  template <class Iterator1, class Iterator2>
63
+ constexpr bool operator!=(
64
  const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
65
  template <class Iterator1, class Iterator2>
66
+ constexpr bool operator<(
67
  const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
68
  template <class Iterator1, class Iterator2>
69
+ constexpr bool operator<=(
70
  const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
71
  template <class Iterator1, class Iterator2>
72
+ constexpr bool operator>(
73
  const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
74
  template <class Iterator1, class Iterator2>
75
+ constexpr bool operator>=(
76
  const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
77
 
78
  template <class Iterator1, class Iterator2>
79
+ constexpr auto operator-(
80
  const move_iterator<Iterator1>& x,
81
  const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
82
  template <class Iterator>
83
+ constexpr move_iterator<Iterator> operator+(
84
  typename move_iterator<Iterator>::difference_type n, const move_iterator<Iterator>& x);
85
  template <class Iterator>
86
+ constexpr move_iterator<Iterator> make_move_iterator(Iterator i);
87
  }
88
  ```
89
 
90
+ Let `R` denote `iterator_traits<Iterator>::reference`. If
91
+ `is_reference_v<R>` is `true`, the template specialization
92
+ `move_iterator<Iterator>` shall define the nested type named `reference`
93
+ as a synonym for `remove_reference_t<R>&&`, otherwise as a synonym for
94
+ `R`.
95
+
96
  #### `move_iterator` requirements <a id="move.iter.requirements">[[move.iter.requirements]]</a>
97
 
98
+ The template parameter `Iterator` shall meet the requirements of an
99
+ input iterator ([[input.iterators]]). Additionally, if any of the
100
  bidirectional or random access traversal functions are instantiated, the
101
  template parameter shall meet the requirements for a Bidirectional
102
  Iterator ([[bidirectional.iterators]]) or a Random Access Iterator (
103
  [[random.access.iterators]]), respectively.
104
 
105
  #### `move_iterator` operations <a id="move.iter.ops">[[move.iter.ops]]</a>
106
 
107
  ##### `move_iterator` constructors <a id="move.iter.op.const">[[move.iter.op.const]]</a>
108
 
109
  ``` cpp
110
+ constexpr move_iterator();
111
  ```
112
 
113
+ *Effects:* Constructs a `move_iterator`, value-initializing `current`.
114
  Iterator operations applied to the resulting iterator have defined
115
  behavior if and only if the corresponding operations are defined on a
116
  value-initialized iterator of type `Iterator`.
117
 
118
  ``` cpp
119
+ constexpr explicit move_iterator(Iterator i);
120
  ```
121
 
122
  *Effects:* Constructs a `move_iterator`, initializing `current` with
123
  `i`.
124
 
125
  ``` cpp
126
+ template <class U> constexpr move_iterator(const move_iterator<U>& u);
127
  ```
128
 
129
  *Effects:* Constructs a `move_iterator`, initializing `current` with
130
  `u.base()`.
131
 
132
  *Requires:* `U` shall be convertible to `Iterator`.
133
 
134
  ##### `move_iterator::operator=` <a id="move.iter.op=">[[move.iter.op=]]</a>
135
 
136
  ``` cpp
137
+ template <class U> constexpr move_iterator& operator=(const move_iterator<U>& u);
138
  ```
139
 
140
  *Effects:* Assigns `u.base()` to `current`.
141
 
142
  *Requires:* `U` shall be convertible to `Iterator`.
143
 
144
  ##### `move_iterator` conversion <a id="move.iter.op.conv">[[move.iter.op.conv]]</a>
145
 
146
  ``` cpp
147
+ constexpr Iterator base() const;
148
  ```
149
 
150
  *Returns:* `current`.
151
 
152
  ##### `move_iterator::operator*` <a id="move.iter.op.star">[[move.iter.op.star]]</a>
153
 
154
  ``` cpp
155
+ constexpr reference operator*() const;
156
  ```
157
 
158
+ *Returns:* `static_cast<reference>(*current)`.
159
 
160
  ##### `move_iterator::operator->` <a id="move.iter.op.ref">[[move.iter.op.ref]]</a>
161
 
162
  ``` cpp
163
+ constexpr pointer operator->() const;
164
  ```
165
 
166
  *Returns:* `current`.
167
 
168
  ##### `move_iterator::operator++` <a id="move.iter.op.incr">[[move.iter.op.incr]]</a>
169
 
170
  ``` cpp
171
+ constexpr move_iterator& operator++();
172
  ```
173
 
174
+ *Effects:* As if by `++current`.
175
 
176
  *Returns:* `*this`.
177
 
178
  ``` cpp
179
+ constexpr move_iterator operator++(int);
180
  ```
181
 
182
+ *Effects:* As if by:
183
 
184
  ``` cpp
185
  move_iterator tmp = *this;
186
  ++current;
187
  return tmp;
188
  ```
189
 
190
  ##### `move_iterator::operator-{-}` <a id="move.iter.op.decr">[[move.iter.op.decr]]</a>
191
 
192
  ``` cpp
193
+ constexpr move_iterator& operator--();
194
  ```
195
 
196
+ *Effects:* As if by `current`.
197
 
198
  *Returns:* `*this`.
199
 
200
  ``` cpp
201
+ constexpr move_iterator operator--(int);
202
  ```
203
 
204
+ *Effects:* As if by:
205
 
206
  ``` cpp
207
  move_iterator tmp = *this;
208
  --current;
209
  return tmp;
210
  ```
211
 
212
  ##### `move_iterator::operator+` <a id="move.iter.op.+">[[move.iter.op.+]]</a>
213
 
214
  ``` cpp
215
+ constexpr move_iterator operator+(difference_type n) const;
216
  ```
217
 
218
  *Returns:* `move_iterator(current + n)`.
219
 
220
  ##### `move_iterator::operator+=` <a id="move.iter.op.+=">[[move.iter.op.+=]]</a>
221
 
222
  ``` cpp
223
+ constexpr move_iterator& operator+=(difference_type n);
224
  ```
225
 
226
+ *Effects:* As if by: `current += n;`
227
 
228
  *Returns:* `*this`.
229
 
230
  ##### `move_iterator::operator-` <a id="move.iter.op.-">[[move.iter.op.-]]</a>
231
 
232
  ``` cpp
233
+ constexpr move_iterator operator-(difference_type n) const;
234
  ```
235
 
236
  *Returns:* `move_iterator(current - n)`.
237
 
238
  ##### `move_iterator::operator-=` <a id="move.iter.op.-=">[[move.iter.op.-=]]</a>
239
 
240
  ``` cpp
241
+ constexpr move_iterator& operator-=(difference_type n);
242
  ```
243
 
244
+ *Effects:* As if by: `current -= n;`
245
 
246
  *Returns:* `*this`.
247
 
248
  ##### `move_iterator::operator[]` <a id="move.iter.op.index">[[move.iter.op.index]]</a>
249
 
250
  ``` cpp
251
+ constexpr unspecified operator[](difference_type n) const;
252
  ```
253
 
254
+ *Returns:* `std::move(current[n])`.
255
 
256
  ##### `move_iterator` comparisons <a id="move.iter.op.comp">[[move.iter.op.comp]]</a>
257
 
258
  ``` cpp
259
  template <class Iterator1, class Iterator2>
260
+ constexpr bool operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
261
  ```
262
 
263
  *Returns:* `x.base() == y.base()`.
264
 
265
  ``` cpp
266
  template <class Iterator1, class Iterator2>
267
+ constexpr bool operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
268
  ```
269
 
270
  *Returns:* `!(x == y)`.
271
 
272
  ``` cpp
273
  template <class Iterator1, class Iterator2>
274
+ constexpr bool operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
275
  ```
276
 
277
  *Returns:* `x.base() < y.base()`.
278
 
279
  ``` cpp
280
  template <class Iterator1, class Iterator2>
281
+ constexpr bool operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
282
  ```
283
 
284
  *Returns:* `!(y < x)`.
285
 
286
  ``` cpp
287
  template <class Iterator1, class Iterator2>
288
+ constexpr bool operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
289
  ```
290
 
291
  *Returns:* `y < x`.
292
 
293
  ``` cpp
294
  template <class Iterator1, class Iterator2>
295
+ constexpr bool operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
296
  ```
297
 
298
  *Returns:* `!(x < y)`.
299
 
300
  ##### `move_iterator` non-member functions <a id="move.iter.nonmember">[[move.iter.nonmember]]</a>
301
 
302
  ``` cpp
303
  template <class Iterator1, class Iterator2>
304
+ constexpr auto operator-(
305
  const move_iterator<Iterator1>& x,
306
  const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
307
  ```
308
 
309
  *Returns:* `x.base() - y.base()`.
310
 
311
  ``` cpp
312
  template <class Iterator>
313
+ constexpr move_iterator<Iterator> operator+(
314
  typename move_iterator<Iterator>::difference_type n, const move_iterator<Iterator>& x);
315
  ```
316
 
317
  *Returns:* `x + n`.
318
 
319
  ``` cpp
320
  template <class Iterator>
321
+ constexpr move_iterator<Iterator> make_move_iterator(Iterator i);
322
  ```
323
 
324
  *Returns:* `move_iterator<Iterator>(i)`.
325