Transitive const sucks

Janice Caron caron800 at googlemail.com
Tue Sep 11 05:53:50 PDT 2007


What all of these use-cases have in common is the fact that the state is
private

Suppose that all class and struct members which were declared private, were
always mutable, even if the class instance is const.

That would mean you could do this:

 class RandomNumberGenerator;
 {
     private long seed;

     const int rand() /* guarantees not to modify any non-private member
variables */
     {
         seed = f(seed);
         return (seed >> 32);
     }
 }

 const RandomNumberGenerator rng;
 writefln(rng.rand());

In C++, we would have declared seed "private mutable" to achieve the same
thing, but in D we tend to assume that everything in the same module is
"friendly", so why not just let "private" mean "private mutable"?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20070911/4927a2fe/attachment.html>


More information about the Digitalmars-d mailing list