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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Iota view <a id="range.iota">[[range.iota]]</a>
2
+
3
+ #### Overview <a id="range.iota.overview">[[range.iota.overview]]</a>
4
+
5
+ `iota_view` generates a sequence of elements by repeatedly incrementing
6
+ an initial value.
7
+
8
+ The name `views::iota` denotes a customization point object
9
+ [[customization.point.object]]. Given subexpressions `E` and `F`, the
10
+ expressions `views::iota(E)` and `views::iota(E, F)` are
11
+ expression-equivalent to `iota_view{E}` and `iota_view{E, F}`,
12
+ respectively.
13
+
14
+ [*Example 1*:
15
+
16
+ ``` cpp
17
+ for (int i : iota_view{1, 10})
18
+ cout << i << ' '; // prints: 1 2 3 4 5 6 7 8 9
19
+ ```
20
+
21
+ — *end example*]
22
+
23
+ #### Class template `iota_view` <a id="range.iota.view">[[range.iota.view]]</a>
24
+
25
+ ``` cpp
26
+ namespace std::ranges {
27
+ template<class I>
28
+ concept decrementable = // exposition only
29
+ see below;
30
+ template<class I>
31
+ concept advanceable = // exposition only
32
+ see below;
33
+
34
+ template<weakly_incrementable W, semiregular Bound = unreachable_sentinel_t>
35
+ requires weakly-equality-comparable-with<W, Bound> && semiregular<W>
36
+ class iota_view : public view_interface<iota_view<W, Bound>> {
37
+ private:
38
+ // [range.iota.iterator], class iota_view::iterator
39
+ struct iterator; // exposition only
40
+ // [range.iota.sentinel], class iota_view::sentinel
41
+ struct sentinel; // exposition only
42
+ W value_ = W(); // exposition only
43
+ Bound bound_ = Bound(); // exposition only
44
+ public:
45
+ iota_view() = default;
46
+ constexpr explicit iota_view(W value);
47
+ constexpr iota_view(type_identity_t<W> value,
48
+ type_identity_t<Bound> bound);
49
+ constexpr iota_view(iterator first, sentinel last) : iota_view(*first, last.bound_) {}
50
+
51
+ constexpr iterator begin() const;
52
+ constexpr auto end() const;
53
+ constexpr iterator end() const requires same_as<W, Bound>;
54
+
55
+ constexpr auto size() const requires see below;
56
+ };
57
+
58
+ template<class W, class Bound>
59
+ requires (!is-integer-like<W> || !is-integer-like<Bound> ||
60
+ (is-signed-integer-like<W> == is-signed-integer-like<Bound>))
61
+ iota_view(W, Bound) -> iota_view<W, Bound>;
62
+ }
63
+ ```
64
+
65
+ Let `IOTA-DIFF-T(W)` be defined as follows:
66
+
67
+ - If `W` is not an integral type, or if it is an integral type and
68
+ `sizeof(iter_difference_t<W>)` is greater than `sizeof(W)`, then
69
+ `IOTA-DIFF-T(W)` denotes `iter_difference_t<W>`.
70
+ - Otherwise, `IOTA-DIFF-T(W)` is a signed integer type of width greater
71
+ than the width of `W` if such a type exists.
72
+ - Otherwise, `IOTA-DIFF-T(W)` is an unspecified signed-integer-like type
73
+ [[iterator.concept.winc]] of width not less than the width of `W`.
74
+ \[*Note 1*: It is unspecified whether this type satisfies
75
+ `weakly_incrementable`. — *end note*]
76
+
77
+ The exposition-only *decrementable* concept is equivalent to:
78
+
79
+ ``` cpp
80
+ template<class I>
81
+ concept decrementable =
82
+ incrementable<I> && requires(I i) {
83
+ { --i } -> same_as<I&>;
84
+ { i-- } -> same_as<I>;
85
+ };
86
+ ```
87
+
88
+ When an object is in the domain of both pre- and post-decrement, the
89
+ object is said to be *decrementable*.
90
+
91
+ Let `a` and `b` be equal objects of type `I`. `I` models `decrementable`
92
+ only if
93
+
94
+ - If `a` and `b` are decrementable, then the following are all true:
95
+ - `addressof(–a) == addressof(a)`
96
+ - `bool(a– == b)`
97
+ - `bool(((void)a–, a) == –b)`
98
+ - `bool(++(–a) == b)`.
99
+ - If `a` and `b` are incrementable, then `bool(–(++a) == b)`.
100
+
101
+ The exposition-only *advanceable* concept is equivalent to:
102
+
103
+ ``` cpp
104
+ template<class I>
105
+ concept advanceable =
106
+ decrementable<I> && totally_ordered<I> &&
107
+ requires(I i, const I j, const IOTA-DIFF-T(I) n) {
108
+ { i += n } -> same_as<I&>;
109
+ { i -= n } -> same_as<I&>;
110
+ I(j + n);
111
+ I(n + j);
112
+ I(j - n);
113
+ { j - j } -> convertible_to<IOTA-DIFF-T(I)>;
114
+ };
115
+ ```
116
+
117
+ Let `D` be `IOTA-DIFF-T(I)`. Let `a` and `b` be objects of type `I` such
118
+ that `b` is reachable from `a` after `n` applications of `++a`, for some
119
+ value `n` of type `D`. `I` models `advanceable` only if
120
+
121
+ - `(a += n)` is equal to `b`.
122
+ - `addressof(a += n)` is equal to `addressof(a)`.
123
+ - `I(a + n)` is equal to `(a += n)`.
124
+ - For any two positive values `x` and `y` of type `D`, if
125
+ `I(a + D(x + y))` is well-defined, then `I(a + D(x + y))` is equal to
126
+ `I(I(a + x) + y)`.
127
+ - `I(a + D(0))` is equal to `a`.
128
+ - If `I(a + D(n - 1))` is well-defined, then `I(a + n)` is equal to
129
+ `[](I c) { return ++c; }(I(a + D(n - 1)))`.
130
+ - `(b += -n)` is equal to `a`.
131
+ - `(b -= n)` is equal to `a`.
132
+ - `addressof(b -= n)` is equal to `addressof(b)`.
133
+ - `I(b - n)` is equal to `(b -= n)`.
134
+ - `D(b - a)` is equal to `n`.
135
+ - `D(a - b)` is equal to `D(-n)`.
136
+ - `bool(a <= b)` is `true`.
137
+
138
+ ``` cpp
139
+ constexpr explicit iota_view(W value);
140
+ ```
141
+
142
+ *Preconditions:* `Bound` denotes `unreachable_sentinel_t` or `Bound()`
143
+ is reachable from `value`.
144
+
145
+ *Effects:* Initializes *value\_* with `value`.
146
+
147
+ ``` cpp
148
+ constexpr iota_view(type_identity_t<W> value, type_identity_t<Bound> bound);
149
+ ```
150
+
151
+ *Preconditions:* `Bound` denotes `unreachable_sentinel_t` or `bound` is
152
+ reachable from `value`. When `W` and `Bound` model
153
+ `totally_ordered_with`, then `bool(value <= bound)` is `true`.
154
+
155
+ *Effects:* Initializes *value\_* with `value` and *bound\_* with
156
+ `bound`.
157
+
158
+ ``` cpp
159
+ constexpr iterator begin() const;
160
+ ```
161
+
162
+ *Effects:* Equivalent to: `return iterator{`*`value_`*`};`
163
+
164
+ ``` cpp
165
+ constexpr auto end() const;
166
+ ```
167
+
168
+ *Effects:* Equivalent to:
169
+
170
+ ``` cpp
171
+ if constexpr (same_as<Bound, unreachable_sentinel_t>)
172
+ return unreachable_sentinel;
173
+ else
174
+ return sentinel{bound_};
175
+ ```
176
+
177
+ ``` cpp
178
+ constexpr iterator end() const requires same_as<W, Bound>;
179
+ ```
180
+
181
+ *Effects:* Equivalent to: `return iterator{bound_};`
182
+
183
+ ``` cpp
184
+ constexpr auto size() const requires see below;
185
+ ```
186
+
187
+ *Effects:* Equivalent to:
188
+
189
+ ``` cpp
190
+ if constexpr (is-integer-like<W> && is-integer-like<Bound>)
191
+ return (value_ < 0)
192
+ ? ((bound_ < 0)
193
+ ? to-unsigned-like(-value_) - to-unsigned-like(-bound_)
194
+ : to-unsigned-like(bound_) + to-unsigned-like(-value_))
195
+ : to-unsigned-like(bound_) - to-unsigned-like(value_);
196
+ else
197
+ return to-unsigned-like(bound_ - value_);
198
+ ```
199
+
200
+ *Remarks:* The expression in the *requires-clause* is equivalent to
201
+
202
+ ``` cpp
203
+ (same_as<W, Bound> && advanceable<W>) || (integral<W> && integral<Bound>) ||
204
+ sized_sentinel_for<Bound, W>
205
+ ```
206
+
207
+ #### Class `iota_view::iterator` <a id="range.iota.iterator">[[range.iota.iterator]]</a>
208
+
209
+ ``` cpp
210
+ namespace std::ranges {
211
+ template<weakly_incrementable W, semiregular Bound>
212
+ requires weakly-equality-comparable-with<W, Bound>
213
+ struct iota_view<W, Bound>::iterator {
214
+ private:
215
+ W value_ = W(); // exposition only
216
+ public:
217
+ using iterator_concept = see below;
218
+ using iterator_category = input_iterator_tag;
219
+ using value_type = W;
220
+ using difference_type = IOTA-DIFF-T(W);
221
+
222
+ iterator() = default;
223
+ constexpr explicit iterator(W value);
224
+
225
+ constexpr W operator*() const noexcept(is_nothrow_copy_constructible_v<W>);
226
+
227
+ constexpr iterator& operator++();
228
+ constexpr void operator++(int);
229
+ constexpr iterator operator++(int) requires incrementable<W>;
230
+
231
+ constexpr iterator& operator--() requires decrementable<W>;
232
+ constexpr iterator operator--(int) requires decrementable<W>;
233
+
234
+ constexpr iterator& operator+=(difference_type n)
235
+ requires advanceable<W>;
236
+ constexpr iterator& operator-=(difference_type n)
237
+ requires advanceable<W>;
238
+ constexpr W operator[](difference_type n) const
239
+ requires advanceable<W>;
240
+
241
+ friend constexpr bool operator==(const iterator& x, const iterator& y)
242
+ requires equality_comparable<W>;
243
+
244
+ friend constexpr bool operator<(const iterator& x, const iterator& y)
245
+ requires totally_ordered<W>;
246
+ friend constexpr bool operator>(const iterator& x, const iterator& y)
247
+ requires totally_ordered<W>;
248
+ friend constexpr bool operator<=(const iterator& x, const iterator& y)
249
+ requires totally_ordered<W>;
250
+ friend constexpr bool operator>=(const iterator& x, const iterator& y)
251
+ requires totally_ordered<W>;
252
+ friend constexpr auto operator<=>(const iterator& x, const iterator& y)
253
+ requires totally_ordered<W> && three_way_comparable<W>;
254
+
255
+ friend constexpr iterator operator+(iterator i, difference_type n)
256
+ requires advanceable<W>;
257
+ friend constexpr iterator operator+(difference_type n, iterator i)
258
+ requires advanceable<W>;
259
+
260
+ friend constexpr iterator operator-(iterator i, difference_type n)
261
+ requires advanceable<W>;
262
+ friend constexpr difference_type operator-(const iterator& x, const iterator& y)
263
+ requires advanceable<W>;
264
+ };
265
+ }
266
+ ```
267
+
268
+ `iterator::iterator_concept` is defined as follows:
269
+
270
+ - If `W` models `advanceable`, then `iterator_concept` is
271
+ `random_access_iterator_tag`.
272
+ - Otherwise, if `W` models `decrementable`, then `iterator_concept` is
273
+ `bidirectional_iterator_tag`.
274
+ - Otherwise, if `W` models `incrementable`, then `iterator_concept` is
275
+ `forward_iterator_tag`.
276
+ - Otherwise, `iterator_concept` is `input_iterator_tag`.
277
+
278
+ [*Note 1*: Overloads for `iter_move` and `iter_swap` are omitted
279
+ intentionally. — *end note*]
280
+
281
+ ``` cpp
282
+ constexpr explicit iterator(W value);
283
+ ```
284
+
285
+ *Effects:* Initializes *value\_* with `value`.
286
+
287
+ ``` cpp
288
+ constexpr W operator*() const noexcept(is_nothrow_copy_constructible_v<W>);
289
+ ```
290
+
291
+ *Effects:* Equivalent to: `return `*`value_`*`;`
292
+
293
+ [*Note 1*: The `noexcept` clause is needed by the default `iter_move`
294
+ implementation. — *end note*]
295
+
296
+ ``` cpp
297
+ constexpr iterator& operator++();
298
+ ```
299
+
300
+ *Effects:* Equivalent to:
301
+
302
+ ``` cpp
303
+ ++value_;
304
+ return *this;
305
+ ```
306
+
307
+ ``` cpp
308
+ constexpr void operator++(int);
309
+ ```
310
+
311
+ *Effects:* Equivalent to `++*this`.
312
+
313
+ ``` cpp
314
+ constexpr iterator operator++(int) requires incrementable<W>;
315
+ ```
316
+
317
+ *Effects:* Equivalent to:
318
+
319
+ ``` cpp
320
+ auto tmp = *this;
321
+ ++*this;
322
+ return tmp;
323
+ ```
324
+
325
+ ``` cpp
326
+ constexpr iterator& operator--() requires decrementable<W>;
327
+ ```
328
+
329
+ *Effects:* Equivalent to:
330
+
331
+ ``` cpp
332
+ --value_;
333
+ return *this;
334
+ ```
335
+
336
+ ``` cpp
337
+ constexpr iterator operator--(int) requires decrementable<W>;
338
+ ```
339
+
340
+ *Effects:* Equivalent to:
341
+
342
+ ``` cpp
343
+ auto tmp = *this;
344
+ --*this;
345
+ return tmp;
346
+ ```
347
+
348
+ ``` cpp
349
+ constexpr iterator& operator+=(difference_type n)
350
+ requires advanceable<W>;
351
+ ```
352
+
353
+ *Effects:* Equivalent to:
354
+
355
+ ``` cpp
356
+ if constexpr (is-integer-like<W> && !is-signed-integer-like<W>) {
357
+ if (n >= difference_type(0))
358
+ value_ += static_cast<W>(n);
359
+ else
360
+ value_ -= static_cast<W>(-n);
361
+ } else {
362
+ value_ += n;
363
+ }
364
+ return *this;
365
+ ```
366
+
367
+ ``` cpp
368
+ constexpr iterator& operator-=(difference_type n)
369
+ requires advanceable<W>;
370
+ ```
371
+
372
+ *Effects:* Equivalent to:
373
+
374
+ ``` cpp
375
+ if constexpr (is-integer-like<W> && !is-signed-integer-like<W>) {
376
+ if (n >= difference_type(0))
377
+ value_ -= static_cast<W>(n);
378
+ else
379
+ value_ += static_cast<W>(-n);
380
+ } else {
381
+ value_ -= n;
382
+ }
383
+ return *this;
384
+ ```
385
+
386
+ ``` cpp
387
+ constexpr W operator[](difference_type n) const
388
+ requires advanceable<W>;
389
+ ```
390
+
391
+ *Effects:* Equivalent to: `return W(`*`value_`*` + n);`
392
+
393
+ ``` cpp
394
+ friend constexpr bool operator==(const iterator& x, const iterator& y)
395
+ requires equality_comparable<W>;
396
+ ```
397
+
398
+ *Effects:* Equivalent to: `return x.`*`value_`*` == y.`*`value_`*`;`
399
+
400
+ ``` cpp
401
+ friend constexpr bool operator<(const iterator& x, const iterator& y)
402
+ requires totally_ordered<W>;
403
+ ```
404
+
405
+ *Effects:* Equivalent to: `return x.`*`value_`*` < y.`*`value_`*`;`
406
+
407
+ ``` cpp
408
+ friend constexpr bool operator>(const iterator& x, const iterator& y)
409
+ requires totally_ordered<W>;
410
+ ```
411
+
412
+ *Effects:* Equivalent to: `return y < x;`
413
+
414
+ ``` cpp
415
+ friend constexpr bool operator<=(const iterator& x, const iterator& y)
416
+ requires totally_ordered<W>;
417
+ ```
418
+
419
+ *Effects:* Equivalent to: `return !(y < x);`
420
+
421
+ ``` cpp
422
+ friend constexpr bool operator>=(const iterator& x, const iterator& y)
423
+ requires totally_ordered<W>;
424
+ ```
425
+
426
+ *Effects:* Equivalent to: `return !(x < y);`
427
+
428
+ ``` cpp
429
+ friend constexpr auto operator<=>(const iterator& x, const iterator& y)
430
+ requires totally_ordered<W> && three_way_comparable<W>;
431
+ ```
432
+
433
+ *Effects:* Equivalent to: `return x.`*`value_`*` <=> y.`*`value_`*`;`
434
+
435
+ ``` cpp
436
+ friend constexpr iterator operator+(iterator i, difference_type n)
437
+ requires advanceable<W>;
438
+ ```
439
+
440
+ *Effects:* Equivalent to: `return i += n;`
441
+
442
+ ``` cpp
443
+ friend constexpr iterator operator+(difference_type n, iterator i)
444
+ requires advanceable<W>;
445
+ ```
446
+
447
+ *Effects:* Equivalent to: `return i + n;`
448
+
449
+ ``` cpp
450
+ friend constexpr iterator operator-(iterator i, difference_type n)
451
+ requires advanceable<W>;
452
+ ```
453
+
454
+ *Effects:* Equivalent to: `return i -= n;`
455
+
456
+ ``` cpp
457
+ friend constexpr difference_type operator-(const iterator& x, const iterator& y)
458
+ requires advanceable<W>;
459
+ ```
460
+
461
+ *Effects:* Equivalent to:
462
+
463
+ ``` cpp
464
+ using D = difference_type;
465
+ if constexpr (is-integer-like<W>) {
466
+ if constexpr (is-signed-integer-like<W>)
467
+ return D(D(x.value_) - D(y.value_));
468
+ else
469
+ return (y.value_ > x.value_)
470
+ ? D(-D(y.value_ - x.value_))
471
+ : D(x.value_ - y.value_);
472
+ } else {
473
+ return x.value_ - y.value_;
474
+ }
475
+ ```
476
+
477
+ #### Class `iota_view::sentinel` <a id="range.iota.sentinel">[[range.iota.sentinel]]</a>
478
+
479
+ ``` cpp
480
+ namespace std::ranges {
481
+ template<weakly_incrementable W, semiregular Bound>
482
+ requires weakly-equality-comparable-with<W, Bound>
483
+ struct iota_view<W, Bound>::sentinel {
484
+ private:
485
+ Bound bound_ = Bound(); // exposition only
486
+ public:
487
+ sentinel() = default;
488
+ constexpr explicit sentinel(Bound bound);
489
+
490
+ friend constexpr bool operator==(const iterator& x, const sentinel& y);
491
+
492
+ friend constexpr iter_difference_t<W> operator-(const iterator& x, const sentinel& y)
493
+ requires sized_sentinel_for<Bound, W>;
494
+ friend constexpr iter_difference_t<W> operator-(const sentinel& x, const iterator& y)
495
+ requires sized_sentinel_for<Bound, W>;
496
+ };
497
+ }
498
+ ```
499
+
500
+ ``` cpp
501
+ constexpr explicit sentinel(Bound bound);
502
+ ```
503
+
504
+ *Effects:* Initializes *bound\_* with `bound`.
505
+
506
+ ``` cpp
507
+ friend constexpr bool operator==(const iterator& x, const sentinel& y);
508
+ ```
509
+
510
+ *Effects:* Equivalent to: `return x.`*`value_`*` == y.`*`bound_`*`;`
511
+
512
+ ``` cpp
513
+ friend constexpr iter_difference_t<W> operator-(const iterator& x, const sentinel& y)
514
+ requires sized_sentinel_for<Bound, W>;
515
+ ```
516
+
517
+ *Effects:* Equivalent to: `return x.`*`value_`*` - y.`*`bound_`*`;`
518
+
519
+ ``` cpp
520
+ friend constexpr iter_difference_t<W> operator-(const sentinel& x, const iterator& y)
521
+ requires sized_sentinel_for<Bound, W>;
522
+ ```
523
+
524
+ *Effects:* Equivalent to: `return -(y - x);`
525
+