From Jason Turner

[range.transform.iterator]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp29ri5sqs/{from.md → to.md} +293 -0
tmp/tmp29ri5sqs/{from.md → to.md} RENAMED
@@ -0,0 +1,293 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Class template `transform_view::iterator` <a id="range.transform.iterator">[[range.transform.iterator]]</a>
2
+
3
+ ``` cpp
4
+ namespace std::ranges {
5
+ template<input_range V, copy_constructible F>
6
+ requires view<V> && is_object_v<F> &&
7
+ regular_invocable<F&, range_reference_t<V>> &&
8
+ can-reference<invoke_result_t<F&, range_reference_t<V>>>
9
+ template<bool Const>
10
+ class transform_view<V, F>::iterator {
11
+ private:
12
+ using Parent = // exposition only
13
+ conditional_t<Const, const transform_view, transform_view>;
14
+ using Base = // exposition only
15
+ conditional_t<Const, const V, V>;
16
+ iterator_t<Base> current_ = // exposition only
17
+ iterator_t<Base>();
18
+ Parent* parent_ = nullptr; // exposition only
19
+ public:
20
+ using iterator_concept = see below;
21
+ using iterator_category = see below;
22
+ using value_type =
23
+ remove_cvref_t<invoke_result_t<F&, range_reference_t<Base>>>;
24
+ using difference_type = range_difference_t<Base>;
25
+
26
+ iterator() = default;
27
+ constexpr iterator(Parent& parent, iterator_t<Base> current);
28
+ constexpr iterator(iterator<!Const> i)
29
+ requires Const && convertible_to<iterator_t<V>, iterator_t<Base>>;
30
+
31
+ constexpr iterator_t<Base> base() const &
32
+ requires copyable<iterator_t<Base>>;
33
+ constexpr iterator_t<Base> base() &&;
34
+ constexpr decltype(auto) operator*() const
35
+ { return invoke(*parent_->fun_, *current_); }
36
+
37
+ constexpr iterator& operator++();
38
+ constexpr void operator++(int);
39
+ constexpr iterator operator++(int) requires forward_range<Base>;
40
+
41
+ constexpr iterator& operator--() requires bidirectional_range<Base>;
42
+ constexpr iterator operator--(int) requires bidirectional_range<Base>;
43
+
44
+ constexpr iterator& operator+=(difference_type n)
45
+ requires random_access_range<Base>;
46
+ constexpr iterator& operator-=(difference_type n)
47
+ requires random_access_range<Base>;
48
+ constexpr decltype(auto) operator[](difference_type n) const
49
+ requires random_access_range<Base>
50
+ { return invoke(*parent_->fun_, current_[n]); }
51
+
52
+ friend constexpr bool operator==(const iterator& x, const iterator& y)
53
+ requires equality_comparable<iterator_t<Base>>;
54
+
55
+ friend constexpr bool operator<(const iterator& x, const iterator& y)
56
+ requires random_access_range<Base>;
57
+ friend constexpr bool operator>(const iterator& x, const iterator& y)
58
+ requires random_access_range<Base>;
59
+ friend constexpr bool operator<=(const iterator& x, const iterator& y)
60
+ requires random_access_range<Base>;
61
+ friend constexpr bool operator>=(const iterator& x, const iterator& y)
62
+ requires random_access_range<Base>;
63
+ friend constexpr auto operator<=>(const iterator& x, const iterator& y)
64
+ requires random_access_range<Base> && three_way_comparable<iterator_t<Base>>;
65
+
66
+ friend constexpr iterator operator+(iterator i, difference_type n)
67
+ requires random_access_range<Base>;
68
+ friend constexpr iterator operator+(difference_type n, iterator i)
69
+ requires random_access_range<Base>;
70
+
71
+ friend constexpr iterator operator-(iterator i, difference_type n)
72
+ requires random_access_range<Base>;
73
+ friend constexpr difference_type operator-(const iterator& x, const iterator& y)
74
+ requires random_access_range<Base>;
75
+
76
+ friend constexpr decltype(auto) iter_move(const iterator& i)
77
+ noexcept(noexcept(invoke(*i.parent_->fun_, *i.current_)))
78
+ {
79
+ if constexpr (is_lvalue_reference_v<decltype(*i)>)
80
+ return std::move(*i);
81
+ else
82
+ return *i;
83
+ }
84
+
85
+ friend constexpr void iter_swap(const iterator& x, const iterator& y)
86
+ noexcept(noexcept(ranges::iter_swap(x.current_, y.current_)))
87
+ requires indirectly_swappable<iterator_t<Base>>;
88
+ };
89
+ }
90
+ ```
91
+
92
+ `iterator::iterator_concept` is defined as follows:
93
+
94
+ - If `V` models `random_access_range`, then `iterator_concept` denotes
95
+ `random_access_iterator_tag`.
96
+ - Otherwise, if `V` models `bidirectional_range`, then
97
+ `iterator_concept` denotes `bidirectional_iterator_tag`.
98
+ - Otherwise, if `V` models `forward_range`, then `iterator_concept`
99
+ denotes `forward_iterator_tag`.
100
+ - Otherwise, `iterator_concept` denotes `input_iterator_tag`.
101
+
102
+ `iterator::iterator_category` is defined as follows: Let `C` denote the
103
+ type `iterator_traits<iterator_t<Base>>::iterator_category`.
104
+
105
+ - If
106
+ `is_lvalue_reference_v<invoke_result_t<F&, range_reference_t<Base>>>`
107
+ is `true`, then
108
+ - if `C` models `derived_from<contiguous_iterator_tag>`,
109
+ `iterator_category` denotes `random_access_iterator_tag`;
110
+ - otherwise, `iterator_category` denotes `C`.
111
+ - Otherwise, `iterator_category` denotes `input_iterator_tag`.
112
+
113
+ ``` cpp
114
+ constexpr iterator(Parent& parent, iterator_t<Base> current);
115
+ ```
116
+
117
+ *Effects:* Initializes *current\_* with `std::move(current)` and
118
+ *parent\_* with `addressof(parent)`.
119
+
120
+ ``` cpp
121
+ constexpr iterator(iterator<!Const> i)
122
+ requires Const && convertible_to<iterator_t<V>, iterator_t<Base>>;
123
+ ```
124
+
125
+ *Effects:* Initializes *current\_* with `std::move(i.`*`current_`*`)`
126
+ and *parent\_* with `i.`*`parent_`*.
127
+
128
+ ``` cpp
129
+ constexpr iterator_t<Base> base() const &
130
+ requires copyable<iterator_t<Base>>;
131
+ ```
132
+
133
+ *Effects:* Equivalent to: `return `*`current_`*`;`
134
+
135
+ ``` cpp
136
+ constexpr iterator_t<Base> base() &&;
137
+ ```
138
+
139
+ *Effects:* Equivalent to: `return std::move(current_);`
140
+
141
+ ``` cpp
142
+ constexpr iterator& operator++();
143
+ ```
144
+
145
+ *Effects:* Equivalent to:
146
+
147
+ ``` cpp
148
+ ++current_;
149
+ return *this;
150
+ ```
151
+
152
+ ``` cpp
153
+ constexpr void operator++(int);
154
+ ```
155
+
156
+ *Effects:* Equivalent to `++current_`.
157
+
158
+ ``` cpp
159
+ constexpr iterator operator++(int) requires forward_range<Base>;
160
+ ```
161
+
162
+ *Effects:* Equivalent to:
163
+
164
+ ``` cpp
165
+ auto tmp = *this;
166
+ ++*this;
167
+ return tmp;
168
+ ```
169
+
170
+ ``` cpp
171
+ constexpr iterator& operator--() requires bidirectional_range<Base>;
172
+ ```
173
+
174
+ *Effects:* Equivalent to:
175
+
176
+ ``` cpp
177
+ --current_;
178
+ return *this;
179
+ ```
180
+
181
+ ``` cpp
182
+ constexpr iterator operator--(int) requires bidirectional_range<Base>;
183
+ ```
184
+
185
+ *Effects:* Equivalent to:
186
+
187
+ ``` cpp
188
+ auto tmp = *this;
189
+ --*this;
190
+ return tmp;
191
+ ```
192
+
193
+ ``` cpp
194
+ constexpr iterator& operator+=(difference_type n)
195
+ requires random_access_range<Base>;
196
+ ```
197
+
198
+ *Effects:* Equivalent to:
199
+
200
+ ``` cpp
201
+ current_ += n;
202
+ return *this;
203
+ ```
204
+
205
+ ``` cpp
206
+ constexpr iterator& operator-=(difference_type n)
207
+ requires random_access_range<Base>;
208
+ ```
209
+
210
+ *Effects:* Equivalent to:
211
+
212
+ ``` cpp
213
+ current_ -= n;
214
+ return *this;
215
+ ```
216
+
217
+ ``` cpp
218
+ friend constexpr bool operator==(const iterator& x, const iterator& y)
219
+ requires equality_comparable<iterator_t<Base>>;
220
+ ```
221
+
222
+ *Effects:* Equivalent to: `return x.`*`current_`*` == y.`*`current_`*`;`
223
+
224
+ ``` cpp
225
+ friend constexpr bool operator<(const iterator& x, const iterator& y)
226
+ requires random_access_range<Base>;
227
+ ```
228
+
229
+ *Effects:* Equivalent to: `return x.`*`current_`*` < y.`*`current_`*`;`
230
+
231
+ ``` cpp
232
+ friend constexpr bool operator>(const iterator& x, const iterator& y)
233
+ requires random_access_range<Base>;
234
+ ```
235
+
236
+ *Effects:* Equivalent to: `return y < x;`
237
+
238
+ ``` cpp
239
+ friend constexpr bool operator<=(const iterator& x, const iterator& y)
240
+ requires random_access_range<Base>;
241
+ ```
242
+
243
+ *Effects:* Equivalent to: `return !(y < x);`
244
+
245
+ ``` cpp
246
+ friend constexpr bool operator>=(const iterator& x, const iterator& y)
247
+ requires random_access_range<Base>;
248
+ ```
249
+
250
+ *Effects:* Equivalent to: `return !(x < y);`
251
+
252
+ ``` cpp
253
+ friend constexpr auto operator<=>(const iterator& x, const iterator& y)
254
+ requires random_access_range<Base> && three_way_comparable<iterator_t<Base>>;
255
+ ```
256
+
257
+ *Effects:* Equivalent to:
258
+ `return x.`*`current_`*` <=> y.`*`current_`*`;`
259
+
260
+ ``` cpp
261
+ friend constexpr iterator operator+(iterator i, difference_type n)
262
+ requires random_access_range<Base>;
263
+ friend constexpr iterator operator+(difference_type n, iterator i)
264
+ requires random_access_range<Base>;
265
+ ```
266
+
267
+ *Effects:* Equivalent to:
268
+ `return iterator{*i.`*`parent_`*`, i.`*`current_`*` + n};`
269
+
270
+ ``` cpp
271
+ friend constexpr iterator operator-(iterator i, difference_type n)
272
+ requires random_access_range<Base>;
273
+ ```
274
+
275
+ *Effects:* Equivalent to:
276
+ `return iterator{*i.`*`parent_`*`, i.`*`current_`*` - n};`
277
+
278
+ ``` cpp
279
+ friend constexpr difference_type operator-(const iterator& x, const iterator& y)
280
+ requires random_access_range<Base>;
281
+ ```
282
+
283
+ *Effects:* Equivalent to: `return x.`*`current_`*` - y.`*`current_`*`;`
284
+
285
+ ``` cpp
286
+ friend constexpr void iter_swap(const iterator& x, const iterator& y)
287
+ noexcept(noexcept(ranges::iter_swap(x.current_, y.current_)))
288
+ requires indirectly_swappable<iterator_t<Base>>;
289
+ ```
290
+
291
+ *Effects:* Equivalent to
292
+ `ranges::iter_swap(x.`*`current_`*`, y.`*`current_`*`)`.
293
+