From Jason Turner

[range.repeat]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpsmilrv9d/{from.md → to.md} +324 -0
tmp/tmpsmilrv9d/{from.md → to.md} RENAMED
@@ -0,0 +1,324 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Repeat view <a id="range.repeat">[[range.repeat]]</a>
2
+
3
+ #### Overview <a id="range.repeat.overview">[[range.repeat.overview]]</a>
4
+
5
+ `repeat_view` generates a sequence of elements by repeatedly producing
6
+ the same value.
7
+
8
+ The name `views::repeat` denotes a customization point object
9
+ [[customization.point.object]]. Given subexpressions `E` and `F`, the
10
+ expressions `views::repeat(E)` and `views::repeat(E, F)` are
11
+ expression-equivalent to `repeat_view(E)` and `repeat_view(E, F)`,
12
+ respectively.
13
+
14
+ [*Example 1*:
15
+
16
+ ``` cpp
17
+ for (int i : views::repeat(17, 4))
18
+ cout << i << ' ';
19
+ // prints 17 17 17 17
20
+ ```
21
+
22
+ — *end example*]
23
+
24
+ #### Class template `repeat_view` <a id="range.repeat.view">[[range.repeat.view]]</a>
25
+
26
+ ``` cpp
27
+ namespace std::ranges {
28
+ template<class T>
29
+ concept integer-like-with-usable-difference-type = // exposition only
30
+ is-signed-integer-like<T> || (is-integer-like<T> && weakly_incrementable<T>);
31
+
32
+ template<move_constructible T, semiregular Bound = unreachable_sentinel_t>
33
+ requires (is_object_v<T> && same_as<T, remove_cv_t<T>> &&
34
+ (integer-like-with-usable-difference-type<Bound> ||
35
+ same_as<Bound, unreachable_sentinel_t>))
36
+ class repeat_view : public view_interface<repeat_view<T, Bound>> {
37
+ private:
38
+ // [range.repeat.iterator], class repeat_view::iterator
39
+ struct iterator; // exposition only
40
+
41
+ movable-box<T> value_; // exposition only, see [range.move.wrap]
42
+ Bound bound_ = Bound(); // exposition only
43
+
44
+ public:
45
+ repeat_view() requires default_initializable<T> = default;
46
+
47
+ constexpr explicit repeat_view(const T& value, Bound bound = Bound())
48
+ requires copy_constructible<T>;
49
+ constexpr explicit repeat_view(T&& value, Bound bound = Bound());
50
+ template<class... TArgs, class... BoundArgs>
51
+ requires constructible_from<T, TArgs...> &&
52
+ constructible_from<Bound, BoundArgs...>
53
+ constexpr explicit repeat_view(piecewise_construct_t,
54
+ tuple<TArgs...> value_args, tuple<BoundArgs...> bound_args = tuple<>{});
55
+
56
+ constexpr iterator begin() const;
57
+ constexpr iterator end() const requires (!same_as<Bound, unreachable_sentinel_t>);
58
+ constexpr unreachable_sentinel_t end() const noexcept;
59
+
60
+ constexpr auto size() const requires (!same_as<Bound, unreachable_sentinel_t>);
61
+ };
62
+
63
+ template<class T, class Bound>
64
+ repeat_view(T, Bound) -> repeat_view<T, Bound>;
65
+ }
66
+ ```
67
+
68
+ ``` cpp
69
+ constexpr explicit repeat_view(const T& value, Bound bound = Bound())
70
+ requires copy_constructible<T>;
71
+ ```
72
+
73
+ *Preconditions:* If `Bound` is not `unreachable_sentinel_t`,
74
+ `bound` ≥ 0.
75
+
76
+ *Effects:* Initializes *value\_* with `value` and *bound\_* with
77
+ `bound`.
78
+
79
+ ``` cpp
80
+ constexpr explicit repeat_view(T&& value, Bound bound = Bound());
81
+ ```
82
+
83
+ *Preconditions:* If `Bound` is not `unreachable_sentinel_t`,
84
+ `bound` ≥ 0.
85
+
86
+ *Effects:* Initializes *value\_* with `std::move(value)` and *bound\_*
87
+ with `bound`.
88
+
89
+ ``` cpp
90
+ template<class... TArgs, class... BoundArgs>
91
+ requires constructible_from<T, TArgs...> &&
92
+ constructible_from<Bound, BoundArgs...>
93
+ constexpr explicit repeat_view(piecewise_construct_t,
94
+ tuple<TArgs...> value_args, tuple<BoundArgs...> bound_args = tuple<>{});
95
+ ```
96
+
97
+ *Effects:* Initializes *value\_* with
98
+ `make_from_tuple<T>(std::move(value_args))` and initializes *bound\_*
99
+ with `make_from_tuple<Bound>(std::move(bound_args))`. The behavior is
100
+ undefined if `Bound` is not `unreachable_sentinel_t` and *bound\_* is
101
+ negative.
102
+
103
+ ``` cpp
104
+ constexpr iterator begin() const;
105
+ ```
106
+
107
+ *Effects:* Equivalent to:
108
+ `return `*`iterator`*`(addressof(*`*`value_`*`));`
109
+
110
+ ``` cpp
111
+ constexpr iterator end() const requires (!same_as<Bound, unreachable_sentinel_t>);
112
+ ```
113
+
114
+ *Effects:* Equivalent to:
115
+ `return `*`iterator`*`(addressof(*`*`value_`*`), `*`bound_`*`);`
116
+
117
+ ``` cpp
118
+ constexpr unreachable_sentinel_t end() const noexcept;
119
+ ```
120
+
121
+ *Effects:* Equivalent to: `return unreachable_sentinel;`
122
+
123
+ ``` cpp
124
+ constexpr auto size() const requires (!same_as<Bound, unreachable_sentinel_t>);
125
+ ```
126
+
127
+ *Effects:* Equivalent to: `return `*`to-unsigned-like`*`(`*`bound_`*`);`
128
+
129
+ #### Class `repeat_view::iterator` <a id="range.repeat.iterator">[[range.repeat.iterator]]</a>
130
+
131
+ ``` cpp
132
+ namespace std::ranges {
133
+ template<move_constructible T, semiregular Bound>
134
+ requires (is_object_v<T> && same_as<T, remove_cv_t<T>> &&
135
+ (integer-like-with-usable-difference-type<Bound> ||
136
+ same_as<Bound, unreachable_sentinel_t>))
137
+ class repeat_view<T, Bound>::iterator {
138
+ private:
139
+ using index-type = // exposition only
140
+ conditional_t<same_as<Bound, unreachable_sentinel_t>, ptrdiff_t, Bound>;
141
+ const T* value_ = nullptr; // exposition only
142
+ index-type current_ = index-type(); // exposition only
143
+
144
+ constexpr explicit iterator(const T* value, index-type b = index-type()); // exposition only
145
+
146
+ public:
147
+ using iterator_concept = random_access_iterator_tag;
148
+ using iterator_category = random_access_iterator_tag;
149
+ using value_type = T;
150
+ using difference_type = see below;
151
+
152
+ iterator() = default;
153
+
154
+ constexpr const T& operator*() const noexcept;
155
+
156
+ constexpr iterator& operator++();
157
+ constexpr iterator operator++(int);
158
+
159
+ constexpr iterator& operator--();
160
+ constexpr iterator operator--(int);
161
+
162
+ constexpr iterator& operator+=(difference_type n);
163
+ constexpr iterator& operator-=(difference_type n);
164
+ constexpr const T& operator[](difference_type n) const noexcept;
165
+
166
+ friend constexpr bool operator==(const iterator& x, const iterator& y);
167
+ friend constexpr auto operator<=>(const iterator& x, const iterator& y);
168
+
169
+ friend constexpr iterator operator+(iterator i, difference_type n);
170
+ friend constexpr iterator operator+(difference_type n, iterator i);
171
+
172
+ friend constexpr iterator operator-(iterator i, difference_type n);
173
+ friend constexpr difference_type operator-(const iterator& x, const iterator& y);
174
+ };
175
+ }
176
+ ```
177
+
178
+ If `is-signed-integer-like<index-type>` is `true`, the member
179
+ *typedef-name* `difference_type` denotes *`index-type`*. Otherwise, it
180
+ denotes `IOTA-DIFF-T(index-type)` [[range.iota.view]].
181
+
182
+ ``` cpp
183
+ constexpr explicit iterator(const T* value, index-type b = index-type());
184
+ ```
185
+
186
+ *Preconditions:* If `Bound` is not `unreachable_sentinel_t`, `b` ≥ 0.
187
+
188
+ *Effects:* Initializes *value\_* with `value` and *current\_* with `b`.
189
+
190
+ ``` cpp
191
+ constexpr const T& operator*() const noexcept;
192
+ ```
193
+
194
+ *Effects:* Equivalent to: `return *`*`value_`*`;`
195
+
196
+ ``` cpp
197
+ constexpr iterator& operator++();
198
+ ```
199
+
200
+ *Effects:* Equivalent to:
201
+
202
+ ``` cpp
203
+ ++current_;
204
+ return *this;
205
+ ```
206
+
207
+ ``` cpp
208
+ constexpr iterator operator++(int);
209
+ ```
210
+
211
+ *Effects:* Equivalent to:
212
+
213
+ ``` cpp
214
+ auto tmp = *this;
215
+ ++*this;
216
+ return tmp;
217
+ ```
218
+
219
+ ``` cpp
220
+ constexpr iterator& operator--();
221
+ ```
222
+
223
+ *Preconditions:* If `Bound` is not `unreachable_sentinel_t`,
224
+ current_ > 0.
225
+
226
+ *Effects:* Equivalent to:
227
+
228
+ ``` cpp
229
+ --current_;
230
+ return *this;
231
+ ```
232
+
233
+ ``` cpp
234
+ constexpr iterator operator--(int);
235
+ ```
236
+
237
+ *Effects:* Equivalent to:
238
+
239
+ ``` cpp
240
+ auto tmp = *this;
241
+ --*this;
242
+ return tmp;
243
+ ```
244
+
245
+ ``` cpp
246
+ constexpr iterator& operator+=(difference_type n);
247
+ ```
248
+
249
+ *Preconditions:* If `Bound` is not `unreachable_sentinel_t`,
250
+ current_ + `n` ≥ 0.
251
+
252
+ *Effects:* Equivalent to:
253
+
254
+ ``` cpp
255
+ current_ += n;
256
+ return *this;
257
+ ```
258
+
259
+ ``` cpp
260
+ constexpr iterator& operator-=(difference_type n);
261
+ ```
262
+
263
+ *Preconditions:* If `Bound` is not `unreachable_sentinel_t`,
264
+ current_ - `n` ≥ 0.
265
+
266
+ *Effects:* Equivalent to:
267
+
268
+ ``` cpp
269
+ current_ -= n;
270
+ return *this;
271
+ ```
272
+
273
+ ``` cpp
274
+ constexpr const T& operator[](difference_type n) const noexcept;
275
+ ```
276
+
277
+ *Effects:* Equivalent to: `return *(*this + n);`
278
+
279
+ ``` cpp
280
+ friend constexpr bool operator==(const iterator& x, const iterator& y);
281
+ ```
282
+
283
+ *Effects:* Equivalent to: `return x.`*`current_`*` == y.`*`current_`*`;`
284
+
285
+ ``` cpp
286
+ friend constexpr auto operator<=>(const iterator& x, const iterator& y);
287
+ ```
288
+
289
+ *Effects:* Equivalent to:
290
+ `return x.`*`current_`*` <=> y.`*`current_`*`;`
291
+
292
+ ``` cpp
293
+ friend constexpr iterator operator+(iterator i, difference_type n);
294
+ friend constexpr iterator operator+(difference_type n, iterator i);
295
+ ```
296
+
297
+ *Effects:* Equivalent to:
298
+
299
+ ``` cpp
300
+ i += n;
301
+ return i;
302
+ ```
303
+
304
+ ``` cpp
305
+ friend constexpr iterator operator-(iterator i, difference_type n);
306
+ ```
307
+
308
+ *Effects:* Equivalent to:
309
+
310
+ ``` cpp
311
+ i -= n;
312
+ return i;
313
+ ```
314
+
315
+ ``` cpp
316
+ friend constexpr difference_type operator-(const iterator& x, const iterator& y);
317
+ ```
318
+
319
+ *Effects:* Equivalent to:
320
+
321
+ ``` cpp
322
+ return static_cast<difference_type>(x.current_) - static_cast<difference_type>(y.current_);
323
+ ```
324
+