Possible Duplicate:
C++ 'mutable' keyword
When have you used C++ 'mutable' keyword?
I understand what mutable means and how it is used, What I would like to know is what is the real motivation behind its existence. I don’t think the only motivation is to bypass the immutability of this in const member functions I rather think there is something more to it.
I don’t think it is just a means to bypass problems in poorly designed systems? or is it?
An obvious offshoot of the original question when does using mutable makes sense even in a good design?
mutableis part of separating bitwise const from logical const.Basically, what the compiler implements is called bitwise const: it
complains if you try to modify the bits of the actual object in a const
function, but not otherwise. When you write a class, you want to
implement logical const: a const function doesn’t modify the observable
value of the object (where the author of the class defines what is
observable value). Mostly, this is a question of not modifying things,
even when you could (e.g. parts of the value accessed through pointers),
but every so often, there are “bits” in the actual object (as seen by
the compiler) which aren’t part of the observable value: cached values
calculated lazily are the classical example, but one can imagine others:
elements in an intrusive linked list, for example, where moving the
element around in the list requires updating pointers to previous and
next (but where the location of the element in the list is not part of
the element’s observable value).