Transitive const sucks
Janice Caron
caron800 at googlemail.com
Wed Sep 12 07:19:12 PDT 2007
> I suspect he meant "copy on write", but forget to tell us. :-)
Here's an example of copy-on-write:
MyString s = "cat";
MyString t = s; /* Only a reference is copied. Now s and t both
reference the same data */
writefln(t); /* prints "cat" */
/*drum roll*/
t[0] = 'b'; /* Only now is a copy made. Now t is unique, with s=="cat"
and t="bat" */
writefln(s); /* prints "cat" */
writefln(t); /* prints "bat" */
Of course, to implement this - to actually create a class that did
this, you'd need MyString to have some internal state (and therefore,
either non-transitive const, or logical const).
More information about the Digitalmars-d
mailing list