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

4181. Some ranges have negative ssize

Section: 24.7 [iterator.range], 25.3.11 [range.prim.ssize] Status: New Submitter: Casey Carter Opened: 2024-12-13 Last modified: 2024-12-14

Priority: Not Prioritized

View other active issues in [iterator.range].

View all other issues in [iterator.range].

View all issues with New status.

Discussion:

There exist range types R whose size is representable by neither ptrdiff_t nor make-signed-like-t<ranges::range_size_t<R>>, specifically views::iota(size_t(0), size_t(-1)). It's unfortunate that std::ssize and ranges::ssize produce a negative size for such ranges even when their difference type is capable of representing their size (see demo). Perhaps the ssize overloads should return static_cast<common_type_t<ptrdiff_t, iter_difference_t<decltype(meow.begin())>>>(meow.size()) instead when the argument meow models range?

Proposed resolution: