Invariant doesn't apply to declared symbols
Janice Caron
caron800 at googlemail.com
Fri Nov 30 04:43:46 PST 2007
> So here's my latest and greatest idea. What about:
>
> const(C)ref // just the data is const
> const(C) // the data and the pointer are both const
>
> This would give us
>
> const(C) c;
> const(C) ref d;
>
> c = new C: // Error;
> d = new C; // OK
> d.x = 100; // Error
Or...
Since we like function-style type constructors in D:
ref(const(C)) // just the data is const
const(C) // the data and the pointer are both const
In the interests of plain old fashioned common sense, the following
four lines should all be exactly equivalent and interchangeable...
ref const C c;
ref const(C) c;
ref(const C) c;
ref(const(C)) c;
In each case, we are declaring c to be of type C, and then saying that
c is const - except for the actual reference, which isn't. Note that
ref-as-a-type-constructor would naturally be forbidden for
non-reference types, so
ref(const(int)) n;
would be a syntax error, because int isn't a reference type.
(...at least, until we get references in D, at which point we will
then be able to legalise it).
More information about the Digitalmars-d
mailing list