Gotcha with const std.range.chunks
steffenwenz+d at gmail.com
Fri Jul 31 15:37:22 UTC 2020
Right, thank you! The range object needs to be mutated to be
iterated on, that explains it.
Although it looks like the opIndex on this particular range could
Here's a longer code snippet that gives some context on why I
thought I needed a const range object. This Matrix class would
have the chunks range object stored as a private property, and
use it in its opIndex to look up values. I wanted to add the
const qualifier to the opIndex method, since it doesn't mutate
the Matrix state, and that's what surfaced this error.
this(size_t width, size_t height)
this.data = new int[width * height];
this.view = data.chunks(width);
T opIndex(size_t col, size_t row) /*const*/ // FIXME Can't be
const because Chunks.opIndex isn't
auto matrix = new Matrix!int(10, 10);
Oh well, I'll try a different way!
More information about the Digitalmars-d-learn