Is it possible to capture by const reference in a lambda expression?
I want the assignment marked below to fail, for example:
#include
In c++14 using static_cast / const_cast:
[&best_string = static_cast(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