Calling assumeSorted on const(std.container.Array)

Ali Çehreli acehreli at yahoo.com
Sat Mar 25 21:38:20 UTC 2023


On 3/25/23 09:31, Olivier Prat wrote:
> On Saturday, 25 March 2023 at 13:45:36 UTC, Olivier Prat wrote:
>> I'm trying to call assumeSorted on a const(Array) using this code 
>> snippet:
>>
>> [...]
> 
> In a similar fashion, a number of methods in SortedRange do not compile 
> if called on a const(SortedRange) or immutable(SortedRange), such as 
> length, or front. Is this on purpose?

There are a number of interesting points in your original post but I 
couldn't find time to answer all of those.

I can inject this for now: :) assumeSorted returns a range object. The 
concept of a const range object is flawed because by nature iteration of 
a range happens by mutating it: For example, popBack has to do that.

So, it's normal that any range algorithm will assume a non-const object.

Ali



More information about the Digitalmars-d-learn mailing list