I read code like this in c++:
const auto candidate_path = std::invoke([&]() {
if (status == ModuleStatus::SUCCESS || status == ModuleStatus::FAILURE) {
// clear candidate path if the module is finished
return convertToPath(nullptr, false, planner_data);
}
return convertToPath(
observer.lock()->getPathCandidate(), observer.lock()->isExecutionReady(), planner_data);
});
The code creates an anonymous function and capture everything by reference [&](){}
and then it’s called by std::invoke()
, I’d like to see if there is any benefit doing it?
Thanks.