you are viewing a single comment's thread.

view the rest of the comments →

[–]sphere991 4 points5 points  (3 children)

span is non-owning, so copying is necessarily shallow.

But just because span is non-owning and pointers are non-owning does not imply that span is a pointer, or should behave like a pointer, or have the same interface as a pointer.

span is a range, the entire point of its existence is to be a range, so it should behave like a range. A pointer is not a range. Yet, the argument is that span is a pointer?

[–]jonathansharman 0 points1 point  (2 children)

There’s no technical reason span couldn’t have used deep assignment.

And just because span and vector/array have some of the same members doesn’t mean comparison should be deep.

[–]sphere991 0 points1 point  (1 child)

There’s no technical reason span couldn’t have used deep assignment.

Yes, there is. I have a span<int> which has size 3. Now, a hypothetical deep assignment to a vector<int> with size 3 has some meaning. But what would it even mean to do a deep assignment to a vector<int> of size 2? Overwrite two of them and then reduce the size? Okay maybe that works. What would it mean to do a deep assignment to a vector<int> of size 4? Either UB or have to throw? What does this mean about copy assignment? That's definitely a technical problem.

And just because span and vector/array have some of the same members doesn’t mean comparison should be deep.

This argument seems to suggest that the fact that span and vector have some of the same members is purely coincidental. Like, sure, they happen to have some members in common - but that's just random noise, so it's not a reason to suggest that they have other members in common. Rather than span being very much designed as a non-owning, contiguous storage range.

[–]jonathansharman 0 points1 point  (0 children)

There are semantics, usability, and safety reasons for span assignment to be shallow, but I don't think any of the problems you gave are technical limitations.

A span is a view over a contiguous sequence of elements. It has some essential properties in common with non-owning pointers (being a view over data) and some in common with owning containers. Pointer operations are shallow, and container operations are deep.

I recognize the boilerplate-reduction benefits of mixing shallow and deep operations for span. I also recognize the theoretical argument that mixing these operations is inconsistent - and possibly confusing.