Proposal - Revised Syntax for const and final
Nathan Reed
nathaniel.reed at gmail.com
Sat Sep 8 09:15:11 PDT 2007
Janice Caron wrote:
> final(T) would be a type that was similar to T except that it would be
> const, its members would be mutable, and all of its members' members
> would be mutable, etc..
I think this has to be modified to: final(T) would be a type similiar to
T except that its value would be const, but anything accessed indirectly
through its value would be mutable.
This is the same problem already pointed out, that it doesn't make any
sense to have the struct const but its members mutable. The struct *is*
its members. With class references, you can have the reference be const
but the members mutable (or vice versa), and you can do this for
*pointers* to structs, but not for structs themselves.
Hence,
struct S {
int a;
int* p;
}
final(S) s;
s = S(47, 0); // error, s is const
s.a = 47; // error, s is const
*s.p = 47; // ok, value pointed to by p is mutable
Thanks,
Nathan Reed
More information about the Digitalmars-d
mailing list