From Jason Turner

[algorithms.requirements]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpp73mguew/{from.md → to.md} +23 -28
tmp/tmpp73mguew/{from.md → to.md} RENAMED
@@ -4,34 +4,13 @@ All of the algorithms are separated from the particular implementations
4
  of data structures and are parameterized by iterator types. Because of
5
  this, they can work with program-defined data structures, as long as
6
  these data structures have iterator types satisfying the assumptions on
7
  the algorithms.
8
 
9
- The entities defined in the `std::ranges` namespace in this Clause are
10
- not found by argument-dependent name lookup [[basic.lookup.argdep]].
11
- When found by unqualified [[basic.lookup.unqual]] name lookup for the
12
- *postfix-expression* in a function call [[expr.call]], they inhibit
13
- argument-dependent name lookup.
14
-
15
- [*Example 1*:
16
-
17
- ``` cpp
18
- void foo() {
19
- using namespace std::ranges;
20
- std::vector<int> vec{1,2,3};
21
- find(begin(vec), end(vec), 2); // #1
22
- }
23
- ```
24
-
25
- The function call expression at `#1` invokes `std::ranges::find`, not
26
- `std::find`, despite that (a) the iterator type returned from
27
- `begin(vec)` and `end(vec)` may be associated with namespace `std` and
28
- (b) `std::find` is more specialized [[temp.func.order]] than
29
- `std::ranges::find` since the former requires its first two parameters
30
- to have the same type.
31
-
32
- — *end example*]
33
 
34
  For purposes of determining the existence of data races, algorithms
35
  shall not modify objects referenced through an iterator argument unless
36
  the specification requires such modification.
37
 
@@ -160,10 +139,18 @@ and if \[`b`, `a`) denotes a range, the same as those of
160
  iter_difference_t<decltype(b)> n = 0;
161
  for (auto tmp = b; tmp != a; ++tmp) --n;
162
  return n;
163
  ```
164
 
 
 
 
 
 
 
 
 
165
  In the description of the algorithms, given an iterator `a` whose
166
  difference type is `D`, and an expression `n` of integer-like type other
167
  than cv `D`, the semantics of `a + n` and `a - n` are, respectively,
168
  those of `a + D(n)` and `a - D(n)`.
169
 
@@ -171,16 +158,24 @@ In the description of algorithm return values, a sentinel value `s`
171
  denoting the end of a range \[`i`, `s`) is sometimes returned where an
172
  iterator is expected. In these cases, the semantics are as if the
173
  sentinel is converted into an iterator using `ranges::next(i, s)`.
174
 
175
  Overloads of algorithms that take `range` arguments [[range.range]]
176
- behave as if they are implemented by calling `ranges::begin` and
177
- `ranges::end` on the `range`(s) and dispatching to the overload in
178
- namespace `ranges` that takes separate iterator and sentinel arguments.
 
 
 
 
 
 
 
 
179
 
180
  The well-formedness and behavior of a call to an algorithm with an
181
  explicitly-specified template argument list is unspecified, except where
182
  explicitly stated otherwise.
183
 
184
- [*Note 3*: Consequently, an implementation can declare an algorithm
185
  with different template parameters than those presented. — *end note*]
186
 
 
4
  of data structures and are parameterized by iterator types. Because of
5
  this, they can work with program-defined data structures, as long as
6
  these data structures have iterator types satisfying the assumptions on
7
  the algorithms.
8
 
9
+ The entities defined in the `std::ranges` namespace in this Clause and
10
+ specified as function templates are algorithm function objects
11
+ [[alg.func.obj]].
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  For purposes of determining the existence of data races, algorithms
14
  shall not modify objects referenced through an iterator argument unless
15
  the specification requires such modification.
16
 
 
139
  iter_difference_t<decltype(b)> n = 0;
140
  for (auto tmp = b; tmp != a; ++tmp) --n;
141
  return n;
142
  ```
143
 
144
+ For each iterator `i` and sentinel `s` produced from a range `r`, the
145
+ semantics of `s - i` has the same type, value, and value category as
146
+ `ranges::distance(i, s)`.
147
+
148
+ [*Note 3*: The implementation can use `ranges::distance(r)` when that
149
+ produces the same value as `ranges::distance(i, s)`. This can be more
150
+ efficient for sized ranges. — *end note*]
151
+
152
  In the description of the algorithms, given an iterator `a` whose
153
  difference type is `D`, and an expression `n` of integer-like type other
154
  than cv `D`, the semantics of `a + n` and `a - n` are, respectively,
155
  those of `a + D(n)` and `a - D(n)`.
156
 
 
158
  denoting the end of a range \[`i`, `s`) is sometimes returned where an
159
  iterator is expected. In these cases, the semantics are as if the
160
  sentinel is converted into an iterator using `ranges::next(i, s)`.
161
 
162
  Overloads of algorithms that take `range` arguments [[range.range]]
163
+ behave as if they are implemented by dispatching to the overload in
164
+ namespace `ranges` that takes separate iterator and sentinel arguments,
165
+ where for each range argument `r`
166
+
167
+ - a corresponding iterator argument is initialized with
168
+ `ranges::begin(r)` and
169
+ - a corresponding sentinel argument is initialized with
170
+ `ranges::end(r)`, or
171
+ `ranges::next(ranges::{}begin(r), ranges::end(r))` if the type of `r`
172
+ models `forward_range` and computing `ranges::next` meets the
173
+ specified complexity requirements.
174
 
175
  The well-formedness and behavior of a call to an algorithm with an
176
  explicitly-specified template argument list is unspecified, except where
177
  explicitly stated otherwise.
178
 
179
+ [*Note 4*: Consequently, an implementation can declare an algorithm
180
  with different template parameters than those presented. — *end note*]
181