Title
Algorithm requirements don't describe semantics of `s - i` well
Status
wp
Section
[algorithms.requirements]
Submitter
Jonathan Wakely

Created on 2025-11-07.00:00:00 last changed 1 month ago

Messages

Date: 2025-11-11.10:48:55

Proposed resolution:

This wording is relative to N5014.

  1. Modify [algorithms.requirements], as indicated:

    -11- In the description of the algorithms, operator `+` is used for some of the iterator categories for which it does not have to be defined. In these cases the semantics of `a + n` are the same as those of

        auto tmp = a;
        for (; n < 0; ++n) --tmp;
        for (; n > 0; --n) ++tmp;
        return tmp;
    
    Similarly, operator `-` is used for some combinations of iterators and sentinel types for which it does not have to be defined. If [`a`, `b`) denotes a range, the semantics of `b - a` in these cases are the same as those of
        iter_difference_t<decltype(a)> n = 0;
        for (auto tmp = a; tmp != b; ++tmp) ++n;
        return n;
    
    and if [`b`, `a`) denotes a range, the same as those of
        iter_difference_t<decltype(b)> n = 0;
        for (auto tmp = b; tmp != a; ++tmp) --n;
        return n;
    

    For each iterator `i` and sentinel `s` produced from a range `r`, the semantics of `s - i` are the same as those of an expression that has the same type, value, and value category as `ranges::distance(i, s)`.

    [Note 3: The implementation can use `ranges::distance(r)` when that produces the same value as `ranges::distance(i, s)`. This can be more efficient for sized ranges. — end note]

Date: 2025-11-11.10:48:55

[ Kona 2025-11-08; Status changed: Immediate → WP. ]

Date: 2025-11-07.19:18:05

[ Kona 2025-11-07; approved by LWG. Status changed: New → Immediate. ]

Date: 2025-11-07.00:00:00
Addresses US 154-252

“the semantics of `s - i` has” is not grammatically correct. Additionally, “type, value, and value category” are properties of expressions, not “semantics”.

History
Date User Action Args
2025-11-11 10:48:55adminsetmessages: + msg15710
2025-11-11 10:48:55adminsetstatus: immediate -> wp
2025-11-07 19:18:05adminsetmessages: + msg15592
2025-11-07 19:18:05adminsetstatus: new -> immediate
2025-11-07 06:46:59adminsetmessages: + msg15583
2025-11-07 00:00:00admincreate