Requirements for Slicing Ranges
Sebastiaan Koppe
mail at skoppe.eu
Tue Sep 3 13:42:28 UTC 2024
On Monday, 2 September 2024 at 11:53:55 UTC, Paul Backus wrote:
> On Monday, 2 September 2024 at 09:59:04 UTC, Sebastiaan Koppe
> wrote:
>>
>> I briefly wondered how it would work if the range is
>> non-copyable, since taking a slice is effectively taking a
>> copy of the underlying data the range captures (and its
>> lifetime).
>
> Taking a slice does not necessarily copy the range, nor does it
> necessarily copy the range's elements.
>
Apologies, I expressed myself poorly, and I have to admit it is a
bit of a stretch.
I meant that taking a slice often creates another alias to the
same data and/or state or part thereof.
This is in contrast to indexing, which just returns the
underlying item, possible as value.
If you would want to restrict/control a range so much so that you
make it non-copyable, you could argue you would want to avoiding
taking a slice from it as well. It might very well have random
access though, so you would end up with one that exposes indexing
but not slicing.
More information about the Digitalmars-d
mailing list