When should I use SortedRange.release?

Paul Backus snarwin at gmail.com
Fri Apr 23 18:35:25 UTC 2021


On Friday, 23 April 2021 at 17:35:13 UTC, Bastiaan Veelo wrote:
> What happens when a range is released?
> What happens if a range is not released?
> What happens if a range is released more than once?
>
> And what does "controlled" imply here? In what way has 
> `SortedRange` control over the underlaying data? What can I do 
> and what can't I do to the underlying data as long as 
> `SortedRange` has control?

I had to look at the source to figure this out. Fortunately, the 
source is pretty simple:

https://phobos.dpldocs.info/source/std.range.d.html#L10833

Turns out, it just calls `core.lifetime.move`. So I guess when 
the docs say "control", what they are really talking about is 
ownership.

Practically speaking, this means that in generic code, we should 
avoid using a `SortedRange` after calling `release`, since we do 
not know whether the range is owning or non-owning w.r.t. the 
underlying data.


More information about the Digitalmars-d-learn mailing list