preparing for const, final, and invariant

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Fri May 18 05:20:52 PDT 2007


Daniel Keep wrote:
>     // Invariant, so a reference to it is fine
>     char[] value(invariant char[] v)
>     {
>         _value = v;
>         return v;
>     }

But a mutable reference to it shouldn't be fine. So IMHO this should 
fail because you're trying to return an invariant char[] as a mutable 
char[]...

>     // Return const: no one calling this can modify it, even though they
>     // have a reference!
>     const char[] value()
>     {
>         return cast(const char[])_value;
>     }

I think that explicit cast should be unneeded. Mutable to const should 
be possible through an implicit cast..



More information about the Digitalmars-d-announce mailing list