Local variables are mutable, unless you explicitly declare them as const
. So there is no need for a mutable specifier on local variables. This is true for stand-alone functions and for class member functions, including const
member functions.
In a const
member function, the "thing" that is const
is the instance of the class that is being operated on (the this
). The local variables are not themselves const
unless you declare them as such.
The only exception is for lambdas. Lambda captured variables are "const by default" because they are members of the capture, and the generated function call operators are const
. You need to declare the lambda as mutable to be able to mutate its state. (Ordinary local variables inside the lambda body are mutable like other ordinary local variables though.)