From Jason Turner

[move.iterators]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpix7t2t3n/{from.md → to.md} +40 -28
tmp/tmpix7t2t3n/{from.md → to.md} RENAMED
@@ -1,7 +1,9 @@
1
  ### Move iterators and sentinels <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.
@@ -24,24 +26,24 @@ vector<string> v2(make_move_iterator(s.begin()),
24
  namespace std {
25
  template<class Iterator>
26
  class move_iterator {
27
  public:
28
  using iterator_type = Iterator;
29
- using iterator_concept = input_iterator_tag;
30
- using iterator_category = see below;
31
  using value_type = iter_value_t<Iterator>;
32
  using difference_type = iter_difference_t<Iterator>;
33
  using pointer = Iterator;
34
  using reference = iter_rvalue_reference_t<Iterator>;
35
 
36
  constexpr move_iterator();
37
  constexpr explicit move_iterator(Iterator i);
38
  template<class U> constexpr move_iterator(const move_iterator<U>& u);
39
  template<class U> constexpr move_iterator& operator=(const move_iterator<U>& u);
40
 
41
- constexpr iterator_type base() const &;
42
- constexpr iterator_type base() &&;
43
  constexpr reference operator*() const;
44
 
45
  constexpr move_iterator& operator++();
46
  constexpr auto operator++(int);
47
  constexpr move_iterator& operator--();
@@ -74,11 +76,23 @@ namespace std {
74
  Iterator current; // exposition only
75
  };
76
  }
77
  ```
78
 
79
- The member *typedef-name* `iterator_category` denotes
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  - `random_access_iterator_tag` if the type
82
  `iterator_traits<{}Iterator>::iterator_category` models
83
  `derived_from<random_access_iterator_tag>`, and
84
  - `iterator_traits<{}Iterator>::iterator_category` otherwise.
@@ -101,49 +115,45 @@ parameter shall either meet the *Cpp17RandomAccessIterator* requirements
101
 
102
  ``` cpp
103
  constexpr move_iterator();
104
  ```
105
 
106
- *Effects:* Constructs a `move_iterator`, value-initializing `current`.
107
- Iterator operations applied to the resulting iterator have defined
108
- behavior if and only if the corresponding operations are defined on a
109
- value-initialized iterator of type `Iterator`.
110
 
111
  ``` cpp
112
  constexpr explicit move_iterator(Iterator i);
113
  ```
114
 
115
- *Effects:* Constructs a `move_iterator`, initializing `current` with
116
- `std::move(i)`.
117
 
118
  ``` cpp
119
  template<class U> constexpr move_iterator(const move_iterator<U>& u);
120
  ```
121
 
122
- *Mandates:* `U` is convertible to `Iterator`.
 
123
 
124
- *Effects:* Constructs a `move_iterator`, initializing `current` with
125
- `u.base()`.
126
 
127
  ``` cpp
128
  template<class U> constexpr move_iterator& operator=(const move_iterator<U>& u);
129
  ```
130
 
131
- *Mandates:* `U` is convertible to `Iterator`.
 
 
132
 
133
- *Effects:* Assigns `u.base()` to `current`.
 
 
134
 
135
  #### Conversion <a id="move.iter.op.conv">[[move.iter.op.conv]]</a>
136
 
137
  ``` cpp
138
- constexpr Iterator base() const &;
139
  ```
140
 
141
- *Constraints:* `Iterator` satisfies `copy_constructible`.
142
-
143
- *Preconditions:* `Iterator` models `copy_constructible`.
144
-
145
  *Returns:* `current`.
146
 
147
  ``` cpp
148
  constexpr Iterator base() &&;
149
  ```
@@ -160,11 +170,11 @@ constexpr reference operator*() const;
160
 
161
  ``` cpp
162
  constexpr reference operator[](difference_type n) const;
163
  ```
164
 
165
- *Effects:* Equivalent to: `ranges::iter_move(current + n);`
166
 
167
  #### Navigation <a id="move.iter.nav">[[move.iter.nav]]</a>
168
 
169
  ``` cpp
170
  constexpr move_iterator& operator++();
@@ -190,11 +200,11 @@ Otherwise, equivalent to `++current`.
190
 
191
  ``` cpp
192
  constexpr move_iterator& operator--();
193
  ```
194
 
195
- *Effects:* As if by `current`.
196
 
197
  *Returns:* `*this`.
198
 
199
  ``` cpp
200
  constexpr move_iterator operator--(int);
@@ -303,12 +313,12 @@ template<class Iterator1, three_way_comparable_with<Iterator1> Iterator2>
303
 
304
  #### Non-member functions <a id="move.iter.nonmember">[[move.iter.nonmember]]</a>
305
 
306
  ``` cpp
307
  template<class Iterator1, class Iterator2>
308
- constexpr auto operator-(const move_iterator<Iterator1>& x,
309
- const move_iterator<Iterator2>& y)
310
  -> decltype(x.base() - y.base());
311
  template<sized_sentinel_for<Iterator> S>
312
  friend constexpr iter_difference_t<Iterator>
313
  operator-(const move_sentinel<S>& x, const move_iterator& y);
314
  template<sized_sentinel_for<Iterator> S>
@@ -322,11 +332,11 @@ template<sized_sentinel_for<Iterator> S>
322
  template<class Iterator>
323
  constexpr move_iterator<Iterator>
324
  operator+(iter_difference_t<Iterator> n, const move_iterator<Iterator>& x);
325
  ```
326
 
327
- *Constraints:* `x + n` is well-formed and has type `Iterator`.
328
 
329
  *Returns:* `x + n`.
330
 
331
  ``` cpp
332
  friend constexpr iter_rvalue_reference_t<Iterator>
@@ -356,11 +366,11 @@ constexpr move_iterator<Iterator> make_move_iterator(Iterator i);
356
 
357
  Class template `move_sentinel` is a sentinel adaptor useful for denoting
358
  ranges together with `move_iterator`. When an input iterator type `I`
359
  and sentinel type `S` model `sentinel_for<S, I>`, `move_sentinel<S>` and
360
  `move_iterator<I>` model
361
- `sentinel_for<move_sentinel<S>, move_iterator<I>{>}` as well.
362
 
363
  [*Example 1*:
364
 
365
  A `move_if` algorithm is easily implemented with `copy_if` using
366
  `move_iterator` and `move_sentinel`:
@@ -368,11 +378,12 @@ A `move_if` algorithm is easily implemented with `copy_if` using
368
  ``` cpp
369
  template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
370
  indirect_unary_predicate<I> Pred>
371
  requires indirectly_movable<I, O>
372
  void move_if(I first, S last, O out, Pred pred) {
373
- std::ranges::copy_if(move_iterator<I>{first}, move_sentinel<S>{last}, out, pred);
 
374
  }
375
  ```
376
 
377
  — *end example*]
378
 
@@ -389,10 +400,11 @@ namespace std {
389
  template<class S2>
390
  requires assignable_from<S&, const S2&>
391
  constexpr move_sentinel& operator=(const move_sentinel<S2>& s);
392
 
393
  constexpr S base() const;
 
394
  private:
395
  S last; // exposition only
396
  };
397
  }
398
  ```
 
1
  ### Move iterators and sentinels <a id="move.iterators">[[move.iterators]]</a>
2
 
3
+ #### General <a id="move.iterators.general">[[move.iterators.general]]</a>
4
+
5
  Class template `move_iterator` is an iterator adaptor with the same
6
  behavior as the underlying iterator except that its indirection operator
7
  implicitly converts the value returned by the underlying iterator’s
8
  indirection operator to an rvalue. Some generic algorithms can be called
9
  with move iterators to replace copying with moving.
 
26
  namespace std {
27
  template<class Iterator>
28
  class move_iterator {
29
  public:
30
  using iterator_type = Iterator;
31
+ using iterator_concept = see below;
32
+ using iterator_category = see below; // not always present
33
  using value_type = iter_value_t<Iterator>;
34
  using difference_type = iter_difference_t<Iterator>;
35
  using pointer = Iterator;
36
  using reference = iter_rvalue_reference_t<Iterator>;
37
 
38
  constexpr move_iterator();
39
  constexpr explicit move_iterator(Iterator i);
40
  template<class U> constexpr move_iterator(const move_iterator<U>& u);
41
  template<class U> constexpr move_iterator& operator=(const move_iterator<U>& u);
42
 
43
+ constexpr const Iterator& base() const & noexcept;
44
+ constexpr Iterator base() &&;
45
  constexpr reference operator*() const;
46
 
47
  constexpr move_iterator& operator++();
48
  constexpr auto operator++(int);
49
  constexpr move_iterator& operator--();
 
76
  Iterator current; // exposition only
77
  };
78
  }
79
  ```
80
 
81
+ The member *typedef-name* `iterator_concept` is defined as follows:
82
+
83
+ - If `Iterator` models `random_access_iterator`, then `iterator_concept`
84
+ denotes `random_access_iterator_tag`.
85
+ - Otherwise, if `Iterator` models `bidirectional_iterator`, then
86
+ `iterator_concept` denotes `bidirectional_iterator_tag`.
87
+ - Otherwise, if `Iterator` models `forward_iterator`, then
88
+ `iterator_concept` denotes `forward_iterator_tag`.
89
+ - Otherwise, `iterator_concept` denotes `input_iterator_tag`.
90
+
91
+ The member *typedef-name* `iterator_category` is defined if and only if
92
+ the *qualified-id* `iterator_traits<Iterator>::iterator_category` is
93
+ valid and denotes a type. In that case, `iterator_category` denotes
94
 
95
  - `random_access_iterator_tag` if the type
96
  `iterator_traits<{}Iterator>::iterator_category` models
97
  `derived_from<random_access_iterator_tag>`, and
98
  - `iterator_traits<{}Iterator>::iterator_category` otherwise.
 
115
 
116
  ``` cpp
117
  constexpr move_iterator();
118
  ```
119
 
120
+ *Effects:* Value-initializes `current`.
 
 
 
121
 
122
  ``` cpp
123
  constexpr explicit move_iterator(Iterator i);
124
  ```
125
 
126
+ *Effects:* Initializes `current` with `std::move(i)`.
 
127
 
128
  ``` cpp
129
  template<class U> constexpr move_iterator(const move_iterator<U>& u);
130
  ```
131
 
132
+ *Constraints:* `is_same_v<U, Iterator>` is `false` and `const U&` models
133
+ `convertible_to<Iterator>`.
134
 
135
+ *Effects:* Initializes `current` with `u.current`.
 
136
 
137
  ``` cpp
138
  template<class U> constexpr move_iterator& operator=(const move_iterator<U>& u);
139
  ```
140
 
141
+ *Constraints:* `is_same_v<U, Iterator>` is `false`, `const U&` models
142
+ `convertible_to<Iterator>`, and `assignable_from<Iterator&, const U&>`
143
+ is modeled.
144
 
145
+ *Effects:* Assigns `u.current` to `current`.
146
+
147
+ *Returns:* `*this`.
148
 
149
  #### Conversion <a id="move.iter.op.conv">[[move.iter.op.conv]]</a>
150
 
151
  ``` cpp
152
+ constexpr const Iterator& base() const & noexcept;
153
  ```
154
 
 
 
 
 
155
  *Returns:* `current`.
156
 
157
  ``` cpp
158
  constexpr Iterator base() &&;
159
  ```
 
170
 
171
  ``` cpp
172
  constexpr reference operator[](difference_type n) const;
173
  ```
174
 
175
+ *Effects:* Equivalent to: `return ranges::iter_move(current + n);`
176
 
177
  #### Navigation <a id="move.iter.nav">[[move.iter.nav]]</a>
178
 
179
  ``` cpp
180
  constexpr move_iterator& operator++();
 
200
 
201
  ``` cpp
202
  constexpr move_iterator& operator--();
203
  ```
204
 
205
+ *Effects:* As if by `current`.
206
 
207
  *Returns:* `*this`.
208
 
209
  ``` cpp
210
  constexpr move_iterator operator--(int);
 
313
 
314
  #### Non-member functions <a id="move.iter.nonmember">[[move.iter.nonmember]]</a>
315
 
316
  ``` cpp
317
  template<class Iterator1, class Iterator2>
318
+ constexpr auto operator-(
319
+ const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y)
320
  -> decltype(x.base() - y.base());
321
  template<sized_sentinel_for<Iterator> S>
322
  friend constexpr iter_difference_t<Iterator>
323
  operator-(const move_sentinel<S>& x, const move_iterator& y);
324
  template<sized_sentinel_for<Iterator> S>
 
332
  template<class Iterator>
333
  constexpr move_iterator<Iterator>
334
  operator+(iter_difference_t<Iterator> n, const move_iterator<Iterator>& x);
335
  ```
336
 
337
+ *Constraints:* `x.base() + n` is well-formed and has type `Iterator`.
338
 
339
  *Returns:* `x + n`.
340
 
341
  ``` cpp
342
  friend constexpr iter_rvalue_reference_t<Iterator>
 
366
 
367
  Class template `move_sentinel` is a sentinel adaptor useful for denoting
368
  ranges together with `move_iterator`. When an input iterator type `I`
369
  and sentinel type `S` model `sentinel_for<S, I>`, `move_sentinel<S>` and
370
  `move_iterator<I>` model
371
+ `sentinel_for<move_sentinel<S>, move_iterator<I>>` as well.
372
 
373
  [*Example 1*:
374
 
375
  A `move_if` algorithm is easily implemented with `copy_if` using
376
  `move_iterator` and `move_sentinel`:
 
378
  ``` cpp
379
  template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
380
  indirect_unary_predicate<I> Pred>
381
  requires indirectly_movable<I, O>
382
  void move_if(I first, S last, O out, Pred pred) {
383
+ ranges::copy_if(move_iterator<I>{std::move(first)}, move_sentinel<S>{last},
384
+ std::move(out), pred);
385
  }
386
  ```
387
 
388
  — *end example*]
389
 
 
400
  template<class S2>
401
  requires assignable_from<S&, const S2&>
402
  constexpr move_sentinel& operator=(const move_sentinel<S2>& s);
403
 
404
  constexpr S base() const;
405
+
406
  private:
407
  S last; // exposition only
408
  };
409
  }
410
  ```