Why are captured-by-value values const, but captured-by-reference objects not:
int a;
auto compile_error = [=]()
{
a = 1;
}
auto compiles_ok = [&]()
{
a = 1;
}
To me this seem illogical but it seem to be the standard? Especially as the unwanted modification of a captured value may be an annoying bug, but chances are high that the consequences are limited to lambda scope, whereas unwanted modification of objects captured by reference will often lead to more serious effects.
So why not capture by const reference per default? Or at least support [const &] and [&]? What are the reasons for this design?
As workaround you are probably supposed to use std::cref wrapped const references captured by value?