Any word on the return-type const syntax?
Janice Caron
caron800 at googlemail.com
Sun Dec 9 08:45:21 PST 2007
It's no good. I just can't figure it out. Let me state a (not
uncommon) problem. See this code:
class A
{
int[] a;
this() { a.length = 4; }
/* K K(int)* p() { return a.ptr } */
}
A m = new A;
const A c = new A;
invariant A i = cast(invariant)new A;
int* mp = m.p();
++mp;
const(int)* cp = c.p();
++cp;
invariant(int)* ip = i.p();
++ip;
Your task is to repace the comment inside class A, with real code,
which has the effect of replacing K by "const", "invariant" or
nothing. (That is, it must, in each case, return the address of a[0]).
The result must compile.
For the life of me, I cannot figure out how to do it. Your
TransferConst! template doesn't seem to be powerful enough to do the
job; I can't overload on the constancy of this ... I'm stuck!
What's the answer?
More information about the Digitalmars-d
mailing list