Title
slide_view::size should preserve the signedness of underlying range's size
Status
nad
Section
[range.slide.view]
Submitter
Hewill Kang

Created on 2022-07-15.00:00:00 last changed 25 months ago

Messages

Date: 2022-11-30.17:59:24

Proposed resolution:

This wording is relative to N4910.

  1. Modify [range.slide.view] as indicated:

    constexpr auto size() requires sized_range<V>;
    constexpr auto size() const requires sized_range<const V>;
    

    -8- Effects: Equivalent to:

    auto sz = ranges::distance(base_) - n_ + 1;
    if (sz < 0) sz = 0;
    return static_cast<decltype(ranges::size(base_))>to-unsigned-like(sz);
    

Date: 2022-11-30.00:00:00

[ 2022-11-30 LWG telecon. Status changed: Tentatively NAD → NAD. ]

Date: 2022-08-15.00:00:00

[ 2022-08-23; Reflector poll: NAD ]

Paper author: "I did consider promotion and decided not to care. The code compiles and conforms to all ranges requirements, and that seems entirely sufficient to me." "Even if we don't outlaw those being different types entirely, people playing those games will still get exactly one unsigned-integer-like type back. It's totally deterministic."

Date: 2022-07-17.12:14:27

Currently, slide_view::size const has the following Effects:

auto sz = ranges::distance(base_) - n_ + 1;
if (sz > 0) sz = 0;
return to-unsigned-like(sz);

There are two problems worth noting here. First, as described in LWG 3739, ranges::distance(base_) and n_ may have different types, which makes the actual type of sz not deterministic. Also, the return type is unconditionally converted to an unsigned type, even though the underlying range may have a signed size type.

Second, even if V has the same difference_type as const V, there may still be integer promotion issues mentioned by LWG 3730 since we add an integer 1 at the end here.

I think converting sz to the size type of the underlying range before returning is the appropriate thing to do.

History
Date User Action Args
2022-11-30 17:59:24adminsetmessages: + msg13137
2022-08-23 15:00:26adminsetmessages: + msg12687
2022-08-23 15:00:26adminsetstatus: new -> nad
2022-07-16 18:04:10adminsetmessages: + msg12596
2022-07-15 00:00:00admincreate