On 9/11/07, <b class="gmail_sendername">Alex Burton</b> &lt;<a href="mailto:alexibu@mac.com">alexibu@mac.com</a>&gt; wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
The idea that you can just &#39;get&#39; a value from memory without modifing anything is an illusion created by the computer.<br></blockquote></div><br>Yes, it&#39;s even more obvious with a read than with a write.<br><br>
Another interesting use-case involves caching. I&#39;ll spare you the boring details, but the essence is, I once had a class member function that did a lookup, much like an associative array, and the prototype would have been something like
<br><br>&nbsp;int lookup(int key) const;<br><br>This was C++, so the const was at the end. The thing is, all the data was in a file, and so the function had to open a file, read it, close the file, and return the data. Well, naturally, it cached some data internally to avoid too many file accesses. And - also naturally - I did not load the entire file into memory at constructor time because huge parts of it might not be needed at all. The file access was deferred until it was needed, and cached appropriately.
<br><br>So the function was declared const, because /conceptually/ it was.<br><br>But the class had a mutable cache, declared with the C++ keyword &quot;mutable&quot;<br><br>Transitivity would wreck that.<br><br>