This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Immediate status.

4462. Algorithm requirements don't describe semantics of s - i well

Section: 26.2 [algorithms.requirements] Status: Immediate Submitter: Jonathan Wakely Opened: 2025-11-07 Last modified: 2025-11-07

Priority: Not Prioritized

View other active issues in [algorithms.requirements].

View all other issues in [algorithms.requirements].

View all issues with Immediate status.

Discussion:

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”.

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

Proposed resolution:

This wording is relative to N5014.

  1. Modify 26.2 [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]