On 3/25/23 9:45 AM, Olivier Prat wrote:

Would someone explain the exact nature of this error as I fail to understand as how just telling that an Array ConstRange is assumed to be sorted actually modifies anything??

It's because a Range keeps a copy of the array (Array is a reference counted type). Since that is labeled `const`, then editing the Range is forbidden.

Inside SortedRange, it has this, which is causing the issue:

```d
    static if (isForwardRange!Range)
    @property auto save()
    {
        // Avoid the constructor
        typeof(this) result = this;
        result._input = _input.save;
        return result;
    }
```

Overwriting the input isn't possible here, because it contains a const member.

Now, this possibly could be fixed with something like:

`return typeof(this)(_input.save);`

But it might just push the error to another place.

The whole thing is kind of ugly.

There is a note inside the Array Range which says it's trying to work around some old bug that is now marked as "works for me", so maybe that can be reexamined.

https://github.com/dlang/phobos/blob/17b1a11afd74f9f8a69af93d77d4548a557e1b89/std/container/array.d#L137

-Steve

Reply via email to