On Sunday, 19 October 2014 at 22:19:05 UTC, Nordlöw wrote:
https://github.com/nordlow/phobos/commit/ce6b9e9ae600b7c28ecddd1e3af7b1516247fb33

now errors as

array.d(927,15): Error: None of the overloads of 'opSlice' are callable using a const object, candidates are: array.d(472,25): std.container.array.Array!int.Array.opSlice() array.d(495,25): std.container.array.Array!int.Array.opSlice(ulong i, ulong j)

The error is because of this (lines 470 through 483):
----
     static if (isMutable!T)
     {
         Range!(Array!T) opSlice()
         {
             return typeof(return)(this, 0, length);
         }
     }
     else
     {
         Range!(const(Array!T)) opSlice() const
         {
             return typeof(return)(this, 0, length);
         }
     }
----

You're disabling the const version when T is mutable. Consider
const(Array!int): T is int is mutable, so there is no const
opSlice. But the Array itself is const, so the non-const version
can't be used. Do not disable the const versions of the methods.
Only ever disable the non-const ones.

Also, the opSlice we're looking at here is Array's, not
Array.Range's. You don't need to touch Array's methods at all.
Only Array.Range's non-const methods need special treatment,
because you need to catch the special case when the Range is
mutable, but the referenced Array is not.

And it's really `isMutableA!`, not `isMutable!T`. I guess you
went for that because `A` is only defined in Array.Range, not in
Array itself. But T's mutability isn't of interest.

For example, Array.Range.opSlice should look like this:
----
         static if (isMutable!A) /* !A, not !T */
         {
             Range!(A) opSlice() {/* ... */}
             Range!(A) opSlice(size_t i, size_t j) {/* ... */}
         }
         /* No `else`, the const versions should always be
available. */
         Range!(const(A)) opSlice() const {/* ... */}
         Range!(const(A)) opSlice(size_t i, size_t j) const {/*
... */}
----

Then there are still various methods of Array.Range left to be
`static if(isMutable!A)` guarded:
* move*
* opIndex
* opSlice*

By the way, since we're in D.learn, I'm assuming you want to do
this yourself. But if you'd like, I could make a pull request
with my suggestions to your branch.

Reply via email to