Re: Physical constness -- what does it mean?
fw@deneb.enyo.de (Florian Weimer) wrote (abridged):
Effective C++, 3rd edition says this:
[...]
| This leads to the notion of logical constness. Adherents to this
| philosophy argue that a _const_ member function might modify some
| of the bits in the object on which it's invoked, but only in
| ways that clients cannot detect. [...]
That's what I'd expect. The meaning of "const" hasn't so much changed as
split into two: physical and logical. These are different but both useful;
it's not a matter of adhering to one philosophy or the other. Logical
const is about interface, and physical const is about implementation.
It's not about objects, but member functions
"Logical const" is about the object's abstract state, as observed through
its public interface. If the abstract state hasn't changed, then calling
the same public member functions with the same arguments must yield the
same results. The physical state may have changed; for example, internal
caches may have been updated, but there's no way to detect this from the
outside.
It's not "about member functions", it's about what can be observed
through the object's public interface. Which will usually involve member
functions.
Use of the keyword "mutable" is one hint that logical const and physical
const are different for an object. The part of the state marked "mutable"
is not ROMable. (I can't find my copy of D&E to check, but you might try
looking up that keyword in it.)
-- Dave Harris, Nottingham, UK.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]