From Jason Turner

[iterators.counted]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmplqofs3lt/{from.md → to.md} +33 -13
tmp/tmplqofs3lt/{from.md → to.md} RENAMED
@@ -21,39 +21,49 @@ ranges::copy(counted_iterator(s.begin(), 10), default_sentinel, back_inserter(v)
21
 
22
  — *end example*]
23
 
24
  Two values `i1` and `i2` of types `counted_iterator<I1>` and
25
  `counted_iterator<I2>` refer to elements of the same sequence if and
26
- only if `next(i1.base(), i1.count())` and `next(i2.base(), i2.count())`
 
27
  refer to the same (possibly past-the-end) element.
28
 
29
  ``` cpp
30
  namespace std {
31
  template<input_or_output_iterator I>
32
  class counted_iterator {
33
  public:
34
  using iterator_type = I;
35
-
36
- constexpr counted_iterator() = default;
 
 
 
 
 
 
37
  constexpr counted_iterator(I x, iter_difference_t<I> n);
38
  template<class I2>
39
  requires convertible_to<const I2&, I>
40
  constexpr counted_iterator(const counted_iterator<I2>& x);
41
 
42
  template<class I2>
43
  requires assignable_from<I&, const I2&>
44
  constexpr counted_iterator& operator=(const counted_iterator<I2>& x);
45
 
46
- constexpr I base() const & requires copy_constructible<I>;
47
  constexpr I base() &&;
48
  constexpr iter_difference_t<I> count() const noexcept;
49
  constexpr decltype(auto) operator*();
50
  constexpr decltype(auto) operator*() const
51
  requires dereferenceable<const I>;
52
 
 
 
 
53
  constexpr counted_iterator& operator++();
54
- decltype(auto) operator++(int);
55
  constexpr counted_iterator operator++(int)
56
  requires forward_iterator<I>;
57
  constexpr counted_iterator& operator--()
58
  requires bidirectional_iterator<I>;
59
  constexpr counted_iterator operator--(int)
@@ -102,18 +112,15 @@ namespace std {
102
  private:
103
  I current = I(); // exposition only
104
  iter_difference_t<I> length = 0; // exposition only
105
  };
106
 
107
- template<class I>
108
- struct incrementable_traits<counted_iterator<I>> {
109
- using difference_type = iter_difference_t<I>;
110
- };
111
-
112
  template<input_iterator I>
 
113
  struct iterator_traits<counted_iterator<I>> : iterator_traits<I> {
114
- using pointer = void;
 
115
  };
116
  }
117
  ```
118
 
119
  #### Constructors and conversions <a id="counted.iter.const">[[counted.iter.const]]</a>
@@ -147,11 +154,11 @@ template<class I2>
147
  *Returns:* `*this`.
148
 
149
  #### Accessors <a id="counted.iter.access">[[counted.iter.access]]</a>
150
 
151
  ``` cpp
152
- constexpr I base() const & requires copy_constructible<I>;
153
  ```
154
 
155
  *Effects:* Equivalent to: `return current;`
156
 
157
  ``` cpp
@@ -172,12 +179,21 @@ constexpr iter_difference_t<I> count() const noexcept;
172
  constexpr decltype(auto) operator*();
173
  constexpr decltype(auto) operator*() const
174
  requires dereferenceable<const I>;
175
  ```
176
 
 
 
177
  *Effects:* Equivalent to: `return *current;`
178
 
 
 
 
 
 
 
 
179
  ``` cpp
180
  constexpr decltype(auto) operator[](iter_difference_t<I> n) const
181
  requires random_access_iterator<I>;
182
  ```
183
 
@@ -200,11 +216,11 @@ constexpr counted_iterator& operator++();
200
  --length;
201
  return *this;
202
  ```
203
 
204
  ``` cpp
205
- decltype(auto) operator++(int);
206
  ```
207
 
208
  *Preconditions:* `length > 0`.
209
 
210
  *Effects:* Equivalent to:
@@ -374,16 +390,20 @@ friend constexpr iter_rvalue_reference_t<I>
374
  iter_move(const counted_iterator& i)
375
  noexcept(noexcept(ranges::iter_move(i.current)))
376
  requires input_iterator<I>;
377
  ```
378
 
 
 
379
  *Effects:* Equivalent to: `return ranges::iter_move(i.current);`
380
 
381
  ``` cpp
382
  template<indirectly_swappable<I> I2>
383
  friend constexpr void
384
  iter_swap(const counted_iterator& x, const counted_iterator<I2>& y)
385
  noexcept(noexcept(ranges::iter_swap(x.current, y.current)));
386
  ```
387
 
 
 
388
  *Effects:* Equivalent to `ranges::iter_swap(x.current, y.current)`.
389
 
 
21
 
22
  — *end example*]
23
 
24
  Two values `i1` and `i2` of types `counted_iterator<I1>` and
25
  `counted_iterator<I2>` refer to elements of the same sequence if and
26
+ only if there exists some integer n such that
27
+ `next(i1.base(), i1.count() + n)` and `next(i2.base(), i2.count() + n)`
28
  refer to the same (possibly past-the-end) element.
29
 
30
  ``` cpp
31
  namespace std {
32
  template<input_or_output_iterator I>
33
  class counted_iterator {
34
  public:
35
  using iterator_type = I;
36
+ using value_type = iter_value_t<I>; // present only
37
+ // if I models indirectly_readable
38
+ using difference_type = iter_difference_t<I>;
39
+ using iterator_concept = typename I::iterator_concept; // present only
40
+ // if the qualified-id I::iterator_concept is valid and denotes a type
41
+ using iterator_category = typename I::iterator_category; // present only
42
+ // if the qualified-id I::iterator_category is valid and denotes a type
43
+ constexpr counted_iterator() requires default_initializable<I> = default;
44
  constexpr counted_iterator(I x, iter_difference_t<I> n);
45
  template<class I2>
46
  requires convertible_to<const I2&, I>
47
  constexpr counted_iterator(const counted_iterator<I2>& x);
48
 
49
  template<class I2>
50
  requires assignable_from<I&, const I2&>
51
  constexpr counted_iterator& operator=(const counted_iterator<I2>& x);
52
 
53
+ constexpr const I& base() const & noexcept;
54
  constexpr I base() &&;
55
  constexpr iter_difference_t<I> count() const noexcept;
56
  constexpr decltype(auto) operator*();
57
  constexpr decltype(auto) operator*() const
58
  requires dereferenceable<const I>;
59
 
60
+ constexpr auto operator->() const noexcept
61
+ requires contiguous_iterator<I>;
62
+
63
  constexpr counted_iterator& operator++();
64
+ constexpr decltype(auto) operator++(int);
65
  constexpr counted_iterator operator++(int)
66
  requires forward_iterator<I>;
67
  constexpr counted_iterator& operator--()
68
  requires bidirectional_iterator<I>;
69
  constexpr counted_iterator operator--(int)
 
112
  private:
113
  I current = I(); // exposition only
114
  iter_difference_t<I> length = 0; // exposition only
115
  };
116
 
 
 
 
 
 
117
  template<input_iterator I>
118
+ requires same_as<ITER_TRAITS(I), iterator_traits<I>> // see [iterator.concepts.general]
119
  struct iterator_traits<counted_iterator<I>> : iterator_traits<I> {
120
+ using pointer = conditional_t<contiguous_iterator<I>,
121
+ add_pointer_t<iter_reference_t<I>>, void>;
122
  };
123
  }
124
  ```
125
 
126
  #### Constructors and conversions <a id="counted.iter.const">[[counted.iter.const]]</a>
 
154
  *Returns:* `*this`.
155
 
156
  #### Accessors <a id="counted.iter.access">[[counted.iter.access]]</a>
157
 
158
  ``` cpp
159
+ constexpr const I& base() const & noexcept;
160
  ```
161
 
162
  *Effects:* Equivalent to: `return current;`
163
 
164
  ``` cpp
 
179
  constexpr decltype(auto) operator*();
180
  constexpr decltype(auto) operator*() const
181
  requires dereferenceable<const I>;
182
  ```
183
 
184
+ *Preconditions:* `length > 0` is `true`.
185
+
186
  *Effects:* Equivalent to: `return *current;`
187
 
188
+ ``` cpp
189
+ constexpr auto operator->() const noexcept
190
+ requires contiguous_iterator<I>;
191
+ ```
192
+
193
+ *Effects:* Equivalent to: `return to_address(current);`
194
+
195
  ``` cpp
196
  constexpr decltype(auto) operator[](iter_difference_t<I> n) const
197
  requires random_access_iterator<I>;
198
  ```
199
 
 
216
  --length;
217
  return *this;
218
  ```
219
 
220
  ``` cpp
221
+ constexpr decltype(auto) operator++(int);
222
  ```
223
 
224
  *Preconditions:* `length > 0`.
225
 
226
  *Effects:* Equivalent to:
 
390
  iter_move(const counted_iterator& i)
391
  noexcept(noexcept(ranges::iter_move(i.current)))
392
  requires input_iterator<I>;
393
  ```
394
 
395
+ *Preconditions:* `i.length > 0` is `true`.
396
+
397
  *Effects:* Equivalent to: `return ranges::iter_move(i.current);`
398
 
399
  ``` cpp
400
  template<indirectly_swappable<I> I2>
401
  friend constexpr void
402
  iter_swap(const counted_iterator& x, const counted_iterator<I2>& y)
403
  noexcept(noexcept(ranges::iter_swap(x.current, y.current)));
404
  ```
405
 
406
+ *Preconditions:* Both `x.length > 0` and `y.length > 0` are `true`.
407
+
408
  *Effects:* Equivalent to `ranges::iter_swap(x.current, y.current)`.
409