From Jason Turner

[iterator.primitives]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpzn1s_8qf/{from.md → to.md} +9 -29
tmp/tmpzn1s_8qf/{from.md → to.md} RENAMED
@@ -140,38 +140,12 @@ possible for a concrete iterator type.
140
  `random_access_iterator` forward `n` steps in constant time. For an
141
  iterator type that does not model `random_access_iterator`,
142
  `ranges::advance` instead performs `n` individual increments with the
143
  `++` operator. — *end example*]
144
 
145
- The function templates defined in [[range.iter.ops]] are not found by
146
- argument-dependent name lookup [[basic.lookup.argdep]]. When found by
147
- unqualified [[basic.lookup.unqual]] name lookup for the
148
- *postfix-expression* in a function call [[expr.call]], they inhibit
149
- argument-dependent name lookup.
150
-
151
- [*Example 2*:
152
-
153
- ``` cpp
154
- void foo() {
155
- using namespace std::ranges;
156
- std::vector<int> vec{1,2,3};
157
- distance(begin(vec), end(vec)); // #1
158
- }
159
- ```
160
-
161
- The function call expression at `#1` invokes `std::ranges::distance`,
162
- not `std::distance`, despite that (a) the iterator type returned from
163
- `begin(vec)` and `end(vec)` may be associated with namespace `std` and
164
- (b) `std::distance` is more specialized [[temp.func.order]] than
165
- `std::ranges::distance` since the former requires its first two
166
- parameters to have the same type.
167
-
168
- — *end example*]
169
-
170
- The number and order of deducible template parameters for the function
171
- templates defined in [[range.iter.ops]] is unspecified, except where
172
- explicitly stated otherwise.
173
 
174
  #### `ranges::advance` <a id="range.iter.op.advance">[[range.iter.op.advance]]</a>
175
 
176
  ``` cpp
177
  template<input_or_output_iterator I>
@@ -245,11 +219,17 @@ number of increments.
245
  template<class I, sized_sentinel_for<decay_t<I>> S>
246
  constexpr iter_difference_t<decay_t<I>> ranges::distance(I&& first, S last);
247
  ```
248
 
249
  *Effects:* Equivalent to:
250
- `return last - static_cast<const decay_t<I>&>(first);`
 
 
 
 
 
 
251
 
252
  ``` cpp
253
  template<range R>
254
  constexpr range_difference_t<R> ranges::distance(R&& r);
255
  ```
 
140
  `random_access_iterator` forward `n` steps in constant time. For an
141
  iterator type that does not model `random_access_iterator`,
142
  `ranges::advance` instead performs `n` individual increments with the
143
  `++` operator. — *end example*]
144
 
145
+ The entities defined in [[range.iter.ops]] are algorithm function
146
+ objects [[alg.func.obj]].
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
 
148
  #### `ranges::advance` <a id="range.iter.op.advance">[[range.iter.op.advance]]</a>
149
 
150
  ``` cpp
151
  template<input_or_output_iterator I>
 
219
  template<class I, sized_sentinel_for<decay_t<I>> S>
220
  constexpr iter_difference_t<decay_t<I>> ranges::distance(I&& first, S last);
221
  ```
222
 
223
  *Effects:* Equivalent to:
224
+
225
+ ``` cpp
226
+ if constexpr (!is_array_v<remove_reference_t<I>>)
227
+ return last - first;
228
+ else
229
+ return last - static_cast<decay_t<I>>(first);
230
+ ```
231
 
232
  ``` cpp
233
  template<range R>
234
  constexpr range_difference_t<R> ranges::distance(R&& r);
235
  ```