Transitive const sucks
Janice Caron
caron800 at googlemail.com
Tue Sep 11 03:29:08 PDT 2007
Your problem generalises to anything "streamy"
Going way back to the old C way of doing things
FILE * f;
fprintf(f, fmt, stuff);
You'd expect that to work, even if you copied from from inside a const
struct, right? But then the type of f would have to change to
const FILE * f;
which is C-speak for "f is a const pointer to mutable FILE". Now throwing in
transitivity would stop it all working.
Moving forward in time to the modern era of objects, in general, you would
want:
stream.write(x);
to work even if the variable "stream" was const. (That is, if the
/reference/ was const, not the data which is pointed to by the reference).
The stack variable can be const, but the heap data needs to be mutable.
I don't have a solution, except to agree that "head const" does seem to be
required after all.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20070911/b36df1c0/attachment.html>
More information about the Digitalmars-d
mailing list