Is it possible to capture by const reference in a lambda expression?
I want the assignment marked below to fail, for example:
using namespace std;
string strings =
static const size_t num_strings = sizeof(strings)/sizeof(strings);
string best_string = "foo";
for_each( &strings, &strings[num_strings], [&best_string](const string& s)
best_string = s; // this should fail
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.