Calling assumeSorted on const(std.container.Array)

Olivier Prat o.prat at free.fr
Sat Mar 25 13:45:36 UTC 2023


I'm trying to call assumeSorted on a const(Array) using this code 
snippet:

     void test(T)(const ref Array!T a)
     {
         auto b = a[].assumeSorted;
         writeln(b);
     }

     void main() {
         Array!int a = [1, 5, 7, 8, 15, 100];
         test(a);
     }

Unfortunately, I keep having a compilation error:
/dlang/dmd/linux/bin64/../../src/phobos/std/range/package.d(10871): Error: cannot modify struct instance `result._input` of type `RangeT!(const(Array!int))` because it contains `const` or `immutable` members
/dlang/dmd/linux/bin64/../../src/phobos/std/range/package.d(10918): Error: cannot modify struct instance `result._input` of type `RangeT!(const(Array!int))` because it contains `const` or `immutable` members
/dlang/dmd/linux/bin64/../../src/phobos/std/range/package.d(11500): Error: template instance `std.range.SortedRange!(RangeT!(const(Array!int)), "a < b", SortedRangeOptions.assumeSorted)` error instantiating
onlineapp.d(10):        instantiated from here: `assumeSorted!("a 
< b", RangeT!(const(Array!int)))`
onlineapp.d(17):        instantiated from here: `test!int`

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??


More information about the Digitalmars-d-learn mailing list