libstdc++: questions about P3663

Tomasz Kaminski tkaminsk@redhat.com
Fri Nov 7 15:54:23 GMT 2025


On Fri, Nov 7, 2025 at 2:11 PM Luc Grosheintz <luc.grosheintz@gmail.com>
wrote:

> Dear libstdc++ devs,
>
> While adding the checking of mandates/prerequisites I
> noticed that:
>
>      7. N5014 requires that for a strided_slice either:
>      slice.extent == 0 or slice.stride > 0.
>
>      However, in P3663, the condition is split into:
>        + constants (8.4.5.3.2): if slice.extent and slice.stride
>           are constant_wrappers, then slice.stride > 0.
>        + runtime (8.4.10.3): either slice.extent == 0 or
>          slice.stride > 0.
>
Cannonicalization process, normalizes stride to cw<1> is extents is cw<0>,
so we reduce number of instantiatons.

  if constexpr (is_same_v<decltype(c_extent),
constant_wrapper<IndexType(0)>>)    return strided_slice{      .offset
= c_offset,      .extent = c_extent,      .stride = cw<IndexType(1)>
 };  else    return strided_slice{      .offset = c_offset,
.extent = c_extent,      .stride =
*canonical-index*<IndexType>(std::move(s.stride))    }



>
> Is this intentional? Essentially, AFAICT,
>    strided_slice{0, cw<0>, cw<0>}; // invalid
>
So this input is turned into  strided_slice{0, cw<0>, cw<1>},
that is not invalid. Again validity is only checked after canoncalization.

>    strided_slice{0, 0, 0}; // valid
>

> Kind regards,
> Luc
>
> On 10/31/25 9:06 AM, Luc Grosheintz wrote:
> > Dear libstdc++ devs,
> >
> > While working on P3663, the following questions arose:
> >
> >    1. What are the requirements for user provided integer-like objects
> >       (when used as slices)? Do they need to have copy and move ctors?
> >       There's a few locations where non-canonicalized slices are copied,
> >       e.g. when passed to `submdspan_canonical_slices`.
> >
> >    2. What happens if in the future the standard wants to add a new kind
> >       of *canonical* selection? For example, block-wise selection: pick
> >       N, skip M, pick N, skip M, etc. This can't be expressed by any of
> >       the current canonical slices (currently there's also no layout to
> >       express this idea, but presumably it would be added at the same
> >       time).
> >
> >    3. Is there a way to `static_assert` the mandate that something is a
> >       "submdspan slice type for IndexType"?
> >
> >    4. The notion of "unit-stride slice" is false for pairs and tuples,
> >       even though they intuitively have unit strides. By renaming the
> >       concept "canonical unit-stride slice", the name would match my
> >       intuition again.
> >
> >    5. There's a notion of "lower bound of the submdspan slice range"
> >       which is also used in contexts where the slice could be empty, e.g.
> >       `strided_slice(n, 0, 1)`. This represents the same empty interval
> >       regardless of the value of `n`, the question is what is the "lower
> >       bound"? Concretely, let `n == exts[i]`. Then, is `pair{n, n}` a
> >       valid slice for dimension `i`? It sounds like yes, because the
> >       condition:
> >         > the kth interval of e contains the submdspan slice range of s
> >           for the kth extent of e;
> >      is satisfied due to the interval being empty. By the same logic,
> >      `pair{n+1, n+1}` should also be valid, but `pair{cw<n+1>, cw<n+1>}`
> >      isn't, because it's not a slice type for the kth extent.
> >
> >    6. I'd like to suggest adding "canonical" to "valid submdspan slice
> >       for the kth extent of e", because:
> >       - a "submdspan slice type for IndexType" is not required to be
> >         canonical,
> >       - there's a couple of related concepts that explicitly mention the
> >         word canonical,
> >       - it makes it harder to know when `SliceSpecifiers` refer to
> >         canonical slices, since that property isn't mentioned and only
> >         implied by "valid submdspan slice for the kth extent of e".
> >
> > Typos:
> >    * In 8.15.2, `src` should be `src.extents()`.
> >
> > Kind regards,
> > Luc
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20251107/0d4f1e47/attachment-0001.htm>


More information about the Libstdc++ mailing list