From Jason Turner

[counted.iterator]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmph1o3_tob/{from.md → to.md} +18 -11
tmp/tmph1o3_tob/{from.md → to.md} RENAMED
@@ -19,39 +19,49 @@ ranges::copy(counted_iterator(s.begin(), 10), default_sentinel, back_inserter(v)
19
 
20
  — *end example*]
21
 
22
  Two values `i1` and `i2` of types `counted_iterator<I1>` and
23
  `counted_iterator<I2>` refer to elements of the same sequence if and
24
- only if `next(i1.base(), i1.count())` and `next(i2.base(), i2.count())`
 
25
  refer to the same (possibly past-the-end) element.
26
 
27
  ``` cpp
28
  namespace std {
29
  template<input_or_output_iterator I>
30
  class counted_iterator {
31
  public:
32
  using iterator_type = I;
33
-
34
- constexpr counted_iterator() = default;
 
 
 
 
 
 
35
  constexpr counted_iterator(I x, iter_difference_t<I> n);
36
  template<class I2>
37
  requires convertible_to<const I2&, I>
38
  constexpr counted_iterator(const counted_iterator<I2>& x);
39
 
40
  template<class I2>
41
  requires assignable_from<I&, const I2&>
42
  constexpr counted_iterator& operator=(const counted_iterator<I2>& x);
43
 
44
- constexpr I base() const & requires copy_constructible<I>;
45
  constexpr I base() &&;
46
  constexpr iter_difference_t<I> count() const noexcept;
47
  constexpr decltype(auto) operator*();
48
  constexpr decltype(auto) operator*() const
49
  requires dereferenceable<const I>;
50
 
 
 
 
51
  constexpr counted_iterator& operator++();
52
- decltype(auto) operator++(int);
53
  constexpr counted_iterator operator++(int)
54
  requires forward_iterator<I>;
55
  constexpr counted_iterator& operator--()
56
  requires bidirectional_iterator<I>;
57
  constexpr counted_iterator operator--(int)
@@ -100,17 +110,14 @@ namespace std {
100
  private:
101
  I current = I(); // exposition only
102
  iter_difference_t<I> length = 0; // exposition only
103
  };
104
 
105
- template<class I>
106
- struct incrementable_traits<counted_iterator<I>> {
107
- using difference_type = iter_difference_t<I>;
108
- };
109
-
110
  template<input_iterator I>
 
111
  struct iterator_traits<counted_iterator<I>> : iterator_traits<I> {
112
- using pointer = void;
 
113
  };
114
  }
115
  ```
116
 
 
19
 
20
  — *end example*]
21
 
22
  Two values `i1` and `i2` of types `counted_iterator<I1>` and
23
  `counted_iterator<I2>` refer to elements of the same sequence if and
24
+ only if there exists some integer n such that
25
+ `next(i1.base(), i1.count() + n)` and `next(i2.base(), i2.count() + n)`
26
  refer to the same (possibly past-the-end) element.
27
 
28
  ``` cpp
29
  namespace std {
30
  template<input_or_output_iterator I>
31
  class counted_iterator {
32
  public:
33
  using iterator_type = I;
34
+ using value_type = iter_value_t<I>; // present only
35
+ // if I models indirectly_readable
36
+ using difference_type = iter_difference_t<I>;
37
+ using iterator_concept = typename I::iterator_concept; // present only
38
+ // if the qualified-id I::iterator_concept is valid and denotes a type
39
+ using iterator_category = typename I::iterator_category; // present only
40
+ // if the qualified-id I::iterator_category is valid and denotes a type
41
+ constexpr counted_iterator() requires default_initializable<I> = default;
42
  constexpr counted_iterator(I x, iter_difference_t<I> n);
43
  template<class I2>
44
  requires convertible_to<const I2&, I>
45
  constexpr counted_iterator(const counted_iterator<I2>& x);
46
 
47
  template<class I2>
48
  requires assignable_from<I&, const I2&>
49
  constexpr counted_iterator& operator=(const counted_iterator<I2>& x);
50
 
51
+ constexpr const I& base() const & noexcept;
52
  constexpr I base() &&;
53
  constexpr iter_difference_t<I> count() const noexcept;
54
  constexpr decltype(auto) operator*();
55
  constexpr decltype(auto) operator*() const
56
  requires dereferenceable<const I>;
57
 
58
+ constexpr auto operator->() const noexcept
59
+ requires contiguous_iterator<I>;
60
+
61
  constexpr counted_iterator& operator++();
62
+ constexpr decltype(auto) operator++(int);
63
  constexpr counted_iterator operator++(int)
64
  requires forward_iterator<I>;
65
  constexpr counted_iterator& operator--()
66
  requires bidirectional_iterator<I>;
67
  constexpr counted_iterator operator--(int)
 
110
  private:
111
  I current = I(); // exposition only
112
  iter_difference_t<I> length = 0; // exposition only
113
  };
114
 
 
 
 
 
 
115
  template<input_iterator I>
116
+ requires same_as<ITER_TRAITS(I), iterator_traits<I>> // see [iterator.concepts.general]
117
  struct iterator_traits<counted_iterator<I>> : iterator_traits<I> {
118
+ using pointer = conditional_t<contiguous_iterator<I>,
119
+ add_pointer_t<iter_reference_t<I>>, void>;
120
  };
121
  }
122
  ```
123