When have you used C++ mutable keyword? and why? I don’t think I have ever had to use that keyword. I understand it is used for things such as caching (or perhaps memorization) but in what class and condition have you ever needed to use it in?
When have you used C++ mutable keyword? and why? I don’t think I have
Share
Occasionally I use it to mark a mutex or other thread synchronisation primitive as being mutable so that accessors/query methods, which are typically marked
constcan still lock the mutex.It’s also sometimes useful when you need to instrument your code for debugging or testing purposes, because instrumentation often needs to modify auxiliary data from inside query methods.