> Variables are default mutable and you have to make them const
Except for the captured variables in a lambda which are const unless you use the mutable keyword. Not a bad idea though.
Except for the captured variables in a lambda which are const unless you use the mutable keyword. Not a bad idea though.
Is there a way to force capture by const-reference by the way?
int main() {
int x = 0;
[&x] { x= 1;}(); // works
[&x=std::as_const(x)] { x= 1;}(); // error: assignment of read-only reference 'x'
}
Not very pretty, but it works.