From Jason Turner

[range.iter.ops]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmphfy06msx/{from.md → to.md} +22 -12
tmp/tmphfy06msx/{from.md → to.md} RENAMED
@@ -1,7 +1,9 @@
1
  ### Range iterator operations <a id="range.iter.ops">[[range.iter.ops]]</a>
2
 
 
 
3
  The library includes the function templates `ranges::advance`,
4
  `ranges::distance`, `ranges::next`, and `ranges::prev` to manipulate
5
  iterators. These operations adapt to the set of operators provided by
6
  each iterator category to provide the most efficient implementation
7
  possible for a concrete iterator type.
@@ -10,11 +12,11 @@ possible for a concrete iterator type.
10
  `random_access_iterator` forward `n` steps in constant time. For an
11
  iterator type that does not model `random_access_iterator`,
12
  `ranges::advance` instead performs `n` individual increments with the
13
  `++` operator. — *end example*]
14
 
15
- The function templates defined in this subclause are not found by
16
  argument-dependent name lookup [[basic.lookup.argdep]]. When found by
17
  unqualified [[basic.lookup.unqual]] name lookup for the
18
  *postfix-expression* in a function call [[expr.call]], they inhibit
19
  argument-dependent name lookup.
20
 
@@ -29,18 +31,18 @@ void foo() {
29
  ```
30
 
31
  The function call expression at `#1` invokes `std::ranges::distance`,
32
  not `std::distance`, despite that (a) the iterator type returned from
33
  `begin(vec)` and `end(vec)` may be associated with namespace `std` and
34
- (b) `std::distance` is more specialized ([[temp.func.order]]) than
35
  `std::ranges::distance` since the former requires its first two
36
  parameters to have the same type.
37
 
38
  — *end example*]
39
 
40
  The number and order of deducible template parameters for the function
41
- templates defined in this subclause is unspecified, except where
42
  explicitly stated otherwise.
43
 
44
  #### `ranges::advance` <a id="range.iter.op.advance">[[range.iter.op.advance]]</a>
45
 
46
  ``` cpp
@@ -60,11 +62,13 @@ not negative.
60
  ``` cpp
61
  template<input_or_output_iterator I, sentinel_for<I> S>
62
  constexpr void ranges::advance(I& i, S bound);
63
  ```
64
 
65
- *Preconditions:* \[`i`, `bound`) denotes a range.
 
 
66
 
67
  *Effects:*
68
 
69
  - If `I` and `S` model `assignable_from<I&, S>`, equivalent to
70
  `i = std::move(bound)`.
@@ -97,21 +101,27 @@ template<input_or_output_iterator I, sentinel_for<I> S>
97
  starting positions of `i`.
98
 
99
  #### `ranges::distance` <a id="range.iter.op.distance">[[range.iter.op.distance]]</a>
100
 
101
  ``` cpp
102
- template<input_or_output_iterator I, sentinel_for<I> S>
 
103
  constexpr iter_difference_t<I> ranges::distance(I first, S last);
104
  ```
105
 
106
- *Preconditions:* \[`first`, `last`) denotes a range, or \[`last`,
107
- `first`) denotes a range and `S` and `I` model
108
- `same_as<S, I> && sized_sentinel_for<S, I>`.
109
 
110
- *Effects:* If `S` and `I` model `sized_sentinel_for<S, I>`, returns
111
- `(last - first)`; otherwise, returns the number of increments needed to
112
- get from `first` to `last`.
 
 
 
 
 
 
 
113
 
114
  ``` cpp
115
  template<range R>
116
  constexpr range_difference_t<R> ranges::distance(R&& r);
117
  ```
@@ -163,11 +173,11 @@ template<input_or_output_iterator I, sentinel_for<I> S>
163
  ``` cpp
164
  template<bidirectional_iterator I>
165
  constexpr I ranges::prev(I x);
166
  ```
167
 
168
- *Effects:* Equivalent to: `-``-``x; return x;`
169
 
170
  ``` cpp
171
  template<bidirectional_iterator I>
172
  constexpr I ranges::prev(I x, iter_difference_t<I> n);
173
  ```
 
1
  ### Range iterator operations <a id="range.iter.ops">[[range.iter.ops]]</a>
2
 
3
+ #### General <a id="range.iter.ops.general">[[range.iter.ops.general]]</a>
4
+
5
  The library includes the function templates `ranges::advance`,
6
  `ranges::distance`, `ranges::next`, and `ranges::prev` to manipulate
7
  iterators. These operations adapt to the set of operators provided by
8
  each iterator category to provide the most efficient implementation
9
  possible for a concrete iterator type.
 
12
  `random_access_iterator` forward `n` steps in constant time. For an
13
  iterator type that does not model `random_access_iterator`,
14
  `ranges::advance` instead performs `n` individual increments with the
15
  `++` operator. — *end example*]
16
 
17
+ The function templates defined in [[range.iter.ops]] are not found by
18
  argument-dependent name lookup [[basic.lookup.argdep]]. When found by
19
  unqualified [[basic.lookup.unqual]] name lookup for the
20
  *postfix-expression* in a function call [[expr.call]], they inhibit
21
  argument-dependent name lookup.
22
 
 
31
  ```
32
 
33
  The function call expression at `#1` invokes `std::ranges::distance`,
34
  not `std::distance`, despite that (a) the iterator type returned from
35
  `begin(vec)` and `end(vec)` may be associated with namespace `std` and
36
+ (b) `std::distance` is more specialized [[temp.func.order]] than
37
  `std::ranges::distance` since the former requires its first two
38
  parameters to have the same type.
39
 
40
  — *end example*]
41
 
42
  The number and order of deducible template parameters for the function
43
+ templates defined in [[range.iter.ops]] is unspecified, except where
44
  explicitly stated otherwise.
45
 
46
  #### `ranges::advance` <a id="range.iter.op.advance">[[range.iter.op.advance]]</a>
47
 
48
  ``` cpp
 
62
  ``` cpp
63
  template<input_or_output_iterator I, sentinel_for<I> S>
64
  constexpr void ranges::advance(I& i, S bound);
65
  ```
66
 
67
+ *Preconditions:* Either
68
+ `assignable_from<I&, S> || sized_sentinel_for<S, I>` is modeled, or
69
+ \[`i`, `bound`) denotes a range.
70
 
71
  *Effects:*
72
 
73
  - If `I` and `S` model `assignable_from<I&, S>`, equivalent to
74
  `i = std::move(bound)`.
 
101
  starting positions of `i`.
102
 
103
  #### `ranges::distance` <a id="range.iter.op.distance">[[range.iter.op.distance]]</a>
104
 
105
  ``` cpp
106
+ template<class I, sentinel_for<I> S>
107
+ requires (!sized_sentinel_for<S, I>)
108
  constexpr iter_difference_t<I> ranges::distance(I first, S last);
109
  ```
110
 
111
+ *Preconditions:* \[`first`, `last`) denotes a range.
 
 
112
 
113
+ *Effects:* Increments `first` until `last` is reached and returns the
114
+ number of increments.
115
+
116
+ ``` cpp
117
+ template<class I, sized_sentinel_for<decay_t<I>> S>
118
+ constexpr iter_difference_t<decay_t<I>> ranges::distance(I&& first, S last);
119
+ ```
120
+
121
+ *Effects:* Equivalent to:
122
+ `return last - static_cast<const decay_t<I>&>(first);`
123
 
124
  ``` cpp
125
  template<range R>
126
  constexpr range_difference_t<R> ranges::distance(R&& r);
127
  ```
 
173
  ``` cpp
174
  template<bidirectional_iterator I>
175
  constexpr I ranges::prev(I x);
176
  ```
177
 
178
+ *Effects:* Equivalent to: `x; return x;`
179
 
180
  ``` cpp
181
  template<bidirectional_iterator I>
182
  constexpr I ranges::prev(I x, iter_difference_t<I> n);
183
  ```