Get rid of std::bind. (#1261)

`std::bind` is bug prone and should be avoided.
Lambdas are a more general and safer replacement.
master
Wolfgang Hess 2018-07-11 20:18:09 +02:00 committed by Wally B. Feed
parent a905036a00
commit 5ad2088561
5 changed files with 30 additions and 11 deletions

View File

@ -110,8 +110,11 @@ MapBuilderServer::MapBuilderServer(
<< "Set either use_trajectory_builder_2d or use_trajectory_builder_3d";
}
map_builder_->pose_graph()->SetGlobalSlamOptimizationCallback(
std::bind(&MapBuilderServer::OnGlobalSlamOptimizations, this,
std::placeholders::_1, std::placeholders::_2));
[this](const std::map<int, mapping::SubmapId>& last_optimized_submap_ids,
const std::map<int, mapping::NodeId>& last_optimized_node_ids) {
OnGlobalSlamOptimizations(last_optimized_submap_ids,
last_optimized_node_ids);
});
}
void MapBuilderServer::Start() {

View File

@ -149,8 +149,10 @@ void PoseGraph2D::AddWorkItem(
if (work_queue_ == nullptr) {
if (work_item() == WorkItem::Result::kRunOptimization) {
work_queue_ = common::make_unique<WorkQueue>();
constraint_builder_.WhenDone(std::bind(&PoseGraph2D::HandleWorkQueue,
this, std::placeholders::_1));
constraint_builder_.WhenDone(
[this](const constraints::ConstraintBuilder2D::Result& result) {
HandleWorkQueue(result);
});
}
} else {
const auto now = std::chrono::steady_clock::now();
@ -437,7 +439,9 @@ void PoseGraph2D::HandleWorkQueue(
LOG(INFO) << "Remaining work items in queue: " << work_queue_->size();
// We have to optimize again.
constraint_builder_.WhenDone(
std::bind(&PoseGraph2D::HandleWorkQueue, this, std::placeholders::_1));
[this](const constraints::ConstraintBuilder2D::Result& result) {
HandleWorkQueue(result);
});
}
void PoseGraph2D::WaitForAllComputations() {

View File

@ -152,7 +152,9 @@ void PoseGraph3D::AddWorkItem(
} else if (work_item() == WorkItem::Result::kRunOptimization) {
work_queue_ = common::make_unique<WorkQueue>();
constraint_builder_.WhenDone(
std::bind(&PoseGraph3D::HandleWorkQueue, this, std::placeholders::_1));
[this](const constraints::ConstraintBuilder3D::Result& result) {
HandleWorkQueue(result);
});
}
}
@ -452,7 +454,9 @@ void PoseGraph3D::HandleWorkQueue(
LOG(INFO) << "Remaining work items in queue: " << work_queue_->size();
// We have to optimize again.
constraint_builder_.WhenDone(
std::bind(&PoseGraph3D::HandleWorkQueue, this, std::placeholders::_1));
[this](const constraints::ConstraintBuilder3D::Result& result) {
HandleWorkQueue(result);
});
}
void PoseGraph3D::WaitForAllComputations() {

View File

@ -60,7 +60,9 @@ TEST_F(ConstraintBuilder2DTest, CallsBack) {
EXPECT_CALL(mock_, Run(::testing::IsEmpty()));
constraint_builder_->NotifyEndOfNode();
constraint_builder_->WhenDone(
std::bind(&MockCallback::Run, &mock_, std::placeholders::_1));
[this](const constraints::ConstraintBuilder2D::Result& result) {
mock_.Run(result);
});
thread_pool_.WaitUntilIdle();
EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), 1);
}
@ -98,7 +100,9 @@ TEST_F(ConstraintBuilder2DTest, FindsConstraints) {
&PoseGraphInterface::Constraint::tag,
PoseGraphInterface::Constraint::INTER_SUBMAP)))));
constraint_builder_->WhenDone(
std::bind(&MockCallback::Run, &mock_, std::placeholders::_1));
[this](const constraints::ConstraintBuilder2D::Result& result) {
mock_.Run(result);
});
thread_pool_.WaitUntilIdle();
constraint_builder_->DeleteScanMatcher(submap_id);
}

View File

@ -63,7 +63,9 @@ TEST_F(ConstraintBuilder3DTest, CallsBack) {
EXPECT_CALL(mock_, Run(::testing::IsEmpty()));
constraint_builder_->NotifyEndOfNode();
constraint_builder_->WhenDone(
std::bind(&MockCallback::Run, &mock_, std::placeholders::_1));
[this](const constraints::ConstraintBuilder3D::Result& result) {
mock_.Run(result);
});
thread_pool_.WaitUntilIdle();
EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), 1);
}
@ -108,7 +110,9 @@ TEST_F(ConstraintBuilder3DTest, FindsConstraints) {
&PoseGraphInterface::Constraint::tag,
PoseGraphInterface::Constraint::INTER_SUBMAP)))));
constraint_builder_->WhenDone(
std::bind(&MockCallback::Run, &mock_, std::placeholders::_1));
[this](const constraints::ConstraintBuilder3D::Result& result) {
mock_.Run(result);
});
thread_pool_.WaitUntilIdle();
constraint_builder_->DeleteScanMatcher(submap_id);
}