On Tue, 27 Mar 2012 04:49:57 -0400, Daniel Donnelly <enjoysm...@gmail.com>
wrote:
The two solutions are:
inout(A) dup() inout { ... }
This transfers the constancy from the object to the result. Is that what
you want? For arrays, dup means "return mutable", no matter what
constancy it is called on.
I'm using the latter. Basically all I need is to copy any object:
const, immut-, or mutable.
BTW, here is what the compiler is complaining about:
immutable B dup();
This is a member function, with the attribute immutable. What this does
is specify that the hidden 'this' pointer is immutable. It's equivalent
to this:
B dup(immutable(B) this);
So what the compiler is saying is that you can't call dup with arguments
(), you must call it with arguments '() immutable', meaning you must call
it on an immutable B, not a mutable B.
-Steve