On Wednesday, 15 October 2014 at 21:15:14 UTC, Nordlöw wrote:
https://github.com/nordlow/phobos/commit/9daf235d7091f76cd941e29e3c167d559bf56a94

but that triggers a new interesting suite of errors

Error: mutable method std.container.array.Array!int.Array.__fieldPostBlit is not callable using a const object
[...]
Error: mutable method std.container.array.Array!int.Array.~this is not callable using a const object
[...]
I'm stuck. Need help.

I reduced it to this:
----
struct RefCounted
{
     this(this) /* const doesn't help */ {}
     ~this() /* const doesn't help */ {}
}
struct Array
{
     RefCounted _data;
}
void main() {const Array a; const copy = a;} /* works */
struct RangeM {Array a;} /* works */
struct RangeC {const Array a;} /* error */
----

Looks like a compiler bug to me.

And here's a workaround:
----
struct RangeC
{
     const Array[1] a_;
     @property ref const(Array) a() {return a_[0];}
}
----

Using it in std.container.array:
----
     static struct Range(A)
     {
         private A[1] _outer_;
         private @property ref const(A) _outer() const {return
_outer_[0];}
         private @property ref A _outer() {return _outer_[0];}
         /* ... */
         private this(ref A data, size_t a, size_t b)
         {
version(none) _outer = data; /* "Error: mutable method
                 [...].Array.opAssign is not callable using a
const object" */
             else version(none) _outer_[0] = data; /* Errors about
postblit. */
             else _outer_ = data; /* works */
             /* ... */
         }
----

Then you also have to disable any methods/overloads that would
return mutable data when A isn't mutable, e.g.:
----
         static if (isMutable!A) @property ref T front() {/* ...
*/}
----

Related: `front` and `back` cannot be inout, because the
constness depends not on Range's constness, but on Array's.

Reply via email to