Title
extents::index-cast weirdness
Status
new
Section
[mdspan.extents.expo]
Submitter
Casey Carter

Created on 2023-11-29.00:00:00 last changed 11 months ago

Messages

Date: 2023-12-02.14:51:47

Proposed resolution:

This wording is relative to N4964.

  1. Modify [mdspan.extents.expo] as indicated:

    template<class OtherIndexType>
      static constexpr auto index-cast(OtherIndexType&& i) noexcept;
    

    -9- Effects:

    1. (9.1) — If remove_cvref_t<OtherIndexType> is an integral type other than bool, then equivalent to return i;,

    2. (9.2) — otherwise, equivalent to return static_cast<index_type>(i);.

    [Note 1: This function will always return an integral type other than bool. Since this function's call sites are constrained on convertibility of OtherIndexType to index_type, integer-class types can use the static_cast branch without loss of precision. — end note]

Date: 2023-11-29.00:00:00

The exposition-only static member index-cast of extents is specified as ([mdspan.extents.expo]/9):

template<class OtherIndexType>
static constexpr auto index-cast(OtherIndexType&& i) noexcept;

-9- Effects:

  1. (9.1) — If OtherIndexType is an integral type other than bool, then equivalent to return i;,

  2. (9.2) — otherwise, equivalent to return static_cast<index_type>(i);.

[Note 1: This function will always return an integral type other than bool. Since this function's call sites are constrained on convertibility of OtherIndexType to index_type, integer-class types can use the static_cast branch without loss of precision. — end note]

This function returns T when passed an rvalue of cv-unqualified integral type T, but index_type when passed a cv-qualified and/or lvalue argument of any integral type. It would seem more consistent and easier to reason about if 9.1 was instead conditional on remove_cvref_t<OtherIndexType>.

History
Date User Action Args
2023-12-02 14:51:47adminsetmessages: + msg13882
2023-11-29 00:00:00admincreate