Issue 3610: iota_view::size sometimes rejects integer-class types (original) (raw)


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

3610. iota_view::size sometimes rejects integer-class types

Section: 25.6.4.2 [range.iota.view] Status: C++23 Submitter: Jiang An Opened: 2021-09-29 Last modified: 2023-11-22

Priority: Not Prioritized

View all other issues in [range.iota.view].

View all issues with C++23 status.

Discussion:

It seems that the iota_view tends to accept integer-class types as its value types, by using _is-integer-like_ or _is-signed-integer-like_ through the specification, although it's unspecified whether any of them satisfies weakly_incrementable. However, the requires-clause of iota_view::size (25.6.4.2 [range.iota.view] p16) uses (integral<W> && integral<Bound>), which sometimes rejects integer-class types.

Should we relax the restrictions by changing this part to (_is-integer-like_<W> && _is-integer-like_<Bound>)?

[2021-10-14; Reflector poll]

Set status to Tentatively Ready after six votes in favour during reflector poll.

[2022-02-10 Approved at February 2022 virtual plenary. Status changed: Tentatively Ready → WP.]

Proposed resolution:

This wording is relative to N4892.

  1. Modify 25.6.4.2 [range.iota.view] as indicated:

    constexpr auto size() const requires see below;

    -15- Effects: Equivalent to:

    if constexpr (is-integer-like && is-integer-like)
    return (value < 0)
    ? ((bound < 0)

 ? _to-unsigned-like_(-_value_) - _to-unsigned-like_(-_bound_)  
 : _to-unsigned-like_(_bound_) + _to-unsigned-like_(-_value_))  

: to-unsigned-like(bound) - to-unsigned-like(value);
else
return to-unsigned-like(bound - value);

-16- Remarks: The expression in the requires-clause is equivalent to:

(same_as<W, Bound> && advanceable) || (integralis-integer-like && integralis-integer-like) ||
sized_sentinel_for<Bound, W>