Lambda capture as const reference?
In c++14 using static_cast
/ const_cast
:
[&best_string = static_cast<const std::string&>(best_string)](const string& s)
{
best_string = s; // fails
};
DEMO
In c++17 using std::as_const
:
[&best_string = std::as_const(best_string)](const string& s)
{
best_string = s; // fails
};
DEMO 2
const
isn't in the grammar for captures as of n3092:
capture:
identifier
& identifier
this
The text only mention capture-by-copy and capture-by-reference and doesn't mention any sort of const-ness.
Feels like an oversight to me, but I haven't followed the standardization process very closely.