lambda capture as const cpp

Solutions on MaxInterview for lambda capture as const cpp by the best coders in the world

showing results for - "lambda capture as const cpp"
Buster
12 Oct 2016
1//In c++14 using static_cast / const_cast:
2
3[&best_string = static_cast<const std::string&>(best_string)](const string& s)
4{
5    best_string = s; // fails
6};
7
Andrea
13 Feb 2016
1//In c++17 using std::as_const:
2
3[&best_string = std::as_const(best_string)](const string& s)
4{
5    best_string = s; // fails
6};
7