On Monday, 8 April 2019 at 18:04:28 UTC, kdevel wrote:
What's the purpose of .release? The documentation in https://dlang.org/phobos/std_range.html#.SortedRange.release is rather monosyllabic.

The sort function returns a SortedRange, which is usually an array wrapper with the extra type information that its content is sorted, enabling certain algorithms like lowerBound and upperBound with help of binary search.

"Ranges whose elements are sorted afford better efficiency with certain operations. For this, the assumeSorted function can be used to construct a SortedRange from a pre-sorted range. The std.algorithm.sorting.sort function also conveniently returns a SortedRange. SortedRange objects provide some additional range operations that take advantage of the fact that the range is sorted."
(https://dlang.org/phobos/std_range.html)

When you release it, you get it back as a normal slice without the type information that it is sorted, so you can assign it to regular old array variables. As mentioned in the quote, you can get it back as sortedRange with assumeSorted.

Reply via email to