From Jason Turner

[counted.iterator]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp2jxhxka0/{from.md → to.md} +116 -0
tmp/tmp2jxhxka0/{from.md → to.md} RENAMED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Class template `counted_iterator` <a id="counted.iterator">[[counted.iterator]]</a>
2
+
3
+ Class template `counted_iterator` is an iterator adaptor with the same
4
+ behavior as the underlying iterator except that it keeps track of the
5
+ distance to the end of its range. It can be used together with
6
+ `default_sentinel` in calls to generic algorithms to operate on a range
7
+ of N elements starting at a given position without needing to know the
8
+ end position a priori.
9
+
10
+ [*Example 1*:
11
+
12
+ ``` cpp
13
+ list<string> s;
14
+ // populate the list s with at least 10 strings
15
+ vector<string> v;
16
+ // copies 10 strings into v:
17
+ ranges::copy(counted_iterator(s.begin(), 10), default_sentinel, back_inserter(v));
18
+ ```
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)
58
+ requires bidirectional_iterator<I>;
59
+
60
+ constexpr counted_iterator operator+(iter_difference_t<I> n) const
61
+ requires random_access_iterator<I>;
62
+ friend constexpr counted_iterator operator+(
63
+ iter_difference_t<I> n, const counted_iterator& x)
64
+ requires random_access_iterator<I>;
65
+ constexpr counted_iterator& operator+=(iter_difference_t<I> n)
66
+ requires random_access_iterator<I>;
67
+
68
+ constexpr counted_iterator operator-(iter_difference_t<I> n) const
69
+ requires random_access_iterator<I>;
70
+ template<common_with<I> I2>
71
+ friend constexpr iter_difference_t<I2> operator-(
72
+ const counted_iterator& x, const counted_iterator<I2>& y);
73
+ friend constexpr iter_difference_t<I> operator-(
74
+ const counted_iterator& x, default_sentinel_t);
75
+ friend constexpr iter_difference_t<I> operator-(
76
+ default_sentinel_t, const counted_iterator& y);
77
+ constexpr counted_iterator& operator-=(iter_difference_t<I> n)
78
+ requires random_access_iterator<I>;
79
+
80
+ constexpr decltype(auto) operator[](iter_difference_t<I> n) const
81
+ requires random_access_iterator<I>;
82
+
83
+ template<common_with<I> I2>
84
+ friend constexpr bool operator==(
85
+ const counted_iterator& x, const counted_iterator<I2>& y);
86
+ friend constexpr bool operator==(
87
+ const counted_iterator& x, default_sentinel_t);
88
+
89
+ template<common_with<I> I2>
90
+ friend constexpr strong_ordering operator<=>(
91
+ const counted_iterator& x, const counted_iterator<I2>& y);
92
+
93
+ friend constexpr iter_rvalue_reference_t<I> iter_move(const counted_iterator& i)
94
+ noexcept(noexcept(ranges::iter_move(i.current)))
95
+ requires input_iterator<I>;
96
+ template<indirectly_swappable<I> I2>
97
+ friend constexpr void iter_swap(const counted_iterator& x, const counted_iterator<I2>& y)
98
+ noexcept(noexcept(ranges::iter_swap(x.current, y.current)));
99
+
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
+