The mutable
keyword applies to the object generated by the lambda expression and not to individually captured items so that it can be implemented by the compiler using a const
modifier on the operator()
method as described in section 5.1.2, paragraph 5 of the standard.
This function call operator is declared const (9.3.1) if and only if
the lambdaexpression’s parameter-declaration-clause is not followed by
mutable.
In your example, the class generated by the lambda expression could look like this:
class lambda
{
int a, b;
public:
lambda( int a, int b ) : a( a ), b( b ) {}
void operator()() // non-const due to mutable keyword
{
a = 7;
}
};