Answers for "Lambda capture as const cpp"

C++
0

Lambda capture as const cpp

//In c++17 using std::as_const:

[&best_string = std::as_const(best_string)](const string& s)
{
    best_string = s; // fails
};
Posted by: Guest on July-23-2021
0

Lambda capture as const cpp

//In c++14 using static_cast / const_cast:

[&best_string = static_cast<const std::string&>(best_string)](const string& s)
{
    best_string = s; // fails
};
Posted by: Guest on July-23-2021

Browse Popular Code Answers by Language