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