Try the following:
struct MyRange(T) { T[] buf; @property ref T front() { return this.buf[0]; } @property ref const(T) front() const { return this.buf[0]; } }
The problem in your example is that you created a front const, but not a return value, and the compiler will not allow you to avoid mutable references to const data like this.
Now, I would like to point out that in general, you should not expect constant ranges to work very well. By their very nature, they must be mutable to popFront over them (since you cannot call popFront in the constant range), so you cannot do much outside the front and empty with the constant range. The situation would not be just as bad if you could implicitly convert a range of constants to a range of tail-constants, but this only works with arrays and no one could find a good way to do this with common ranges. So, unfortunately, constant ranges are currently useless.
Jonathan m davis
source share