libstdc++: Handling user-defined interlike object in submdspan.

Luc Grosheintz luc.grosheintz@gmail.com
Tue Sep 30 07:47:02 GMT 2025



On 9/30/25 8:53 AM, Tomasz Kaminski wrote:
> On Tue, Sep 30, 2025 at 8:30 AM Luc Grosheintz <luc.grosheintz@gmail.com>
> wrote:
> 
>>
>>
>> On 9/29/25 5:18 PM, Jonathan Wakely wrote:
>>>>
>>>> The question is should it support custom types that aren't copyable?
>>>> (Everything is much easier if all types are move and copy
>>>> constructable).
>>>>
>>>
>>> I think this is in flux, via P3663, which is being reviewed by LWG at the
>>> moment. The latest draft (with a lot of input from Tomasz) is
>>> https://isocpp.org/files/papers/D3663R3.html
>>>
>>
>> Thank you, that's interesting. I'll read it again more carefully, but
>> it looks like the proposed casting layer is sensible; and might get
>> added via P3663 (they call it canonicalization). I'll finish a v1
>> with the casting layer.
>>
> My suggestion here would be to implement what P3663 is proposing
> from the start. This is only observable for user-defined mappings, as they
> will no longer obser other slice types than canonical ones.
> 
> As the paper touches a lot of wording, we have fixed some of the issues
> as the drive-by there.

I canonicalize tuple-like to `std::tuple`s of possibly wrapped
index_type; and not to stride<*, *, std::cw<1>>.

The advantage is that the preconditions remain the same, because
tuples still exist, it's just that we don't encounter as much
variability but the kinds of objects remain the same.

Generally, and as written in the paper, it does make sense to maybe
not canonicalize things like:

   - std::array<index_type, 2>
   - std::tuple<std::constant_wrapper<index_type, *>,
                std::constant_wrapper<index_type, *>>

because those are very natural ways of specifying that kind of slice. 
Therefore, even if there's a cost to canonicalization, every kind of
slice has a convenient canonical form (that users can provide to skip
canonicalization).

Is it okay to send this variation as a v1? Naturally, you can then
say: nope, do the full P3663 please.
> 
> 
>>
>>>>
>>>> The idea I'm pursuing is to follow the pattern of casting slices to
>>>> "standard slices" immediately at the user-facing API layer, e.g.
>>>>
>>>>      template<typename _Slices...>
>>>>      constexpr auto
>>>>      submdspan_extents(_Slices... __slices)
>>>>      {
>>>>        return __submdspan_extents(__slice_cast(std::move(__slices))...);
>>>>      }
>>>>
>>
>>
> 



More information about the Libstdc++ mailing list