What all of these use-cases have in common is the fact that the state is private<br><br>Suppose that all class and struct members which were declared private, were always mutable, even if the class instance is const.<br><br>
That would mean you could do this:<br><br>&nbsp;class RandomNumberGenerator;<br>&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp; private long seed;<br>&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp; const int rand() /* guarantees not to modify any non-private member variables */<br>&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seed = f(seed);
<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return (seed &gt;&gt; 32);<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;}<br><br>&nbsp;const RandomNumberGenerator rng;<br>&nbsp;writefln(rng.rand());<br><br>In C++, we would have declared seed &quot;private mutable&quot; to achieve the same thing, but in D we tend to assume that everything in the same module is &quot;friendly&quot;, so why not just let &quot;private&quot; mean &quot;private mutable&quot;?
<br><br><br>