Get rid of std::bind. (#1261)
`std::bind` is bug prone and should be avoided. Lambdas are a more general and safer replacement.master
parent
a905036a00
commit
5ad2088561
|
@ -110,8 +110,11 @@ MapBuilderServer::MapBuilderServer(
|
||||||
<< "Set either use_trajectory_builder_2d or use_trajectory_builder_3d";
|
<< "Set either use_trajectory_builder_2d or use_trajectory_builder_3d";
|
||||||
}
|
}
|
||||||
map_builder_->pose_graph()->SetGlobalSlamOptimizationCallback(
|
map_builder_->pose_graph()->SetGlobalSlamOptimizationCallback(
|
||||||
std::bind(&MapBuilderServer::OnGlobalSlamOptimizations, this,
|
[this](const std::map<int, mapping::SubmapId>& last_optimized_submap_ids,
|
||||||
std::placeholders::_1, std::placeholders::_2));
|
const std::map<int, mapping::NodeId>& last_optimized_node_ids) {
|
||||||
|
OnGlobalSlamOptimizations(last_optimized_submap_ids,
|
||||||
|
last_optimized_node_ids);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapBuilderServer::Start() {
|
void MapBuilderServer::Start() {
|
||||||
|
|
|
@ -149,8 +149,10 @@ void PoseGraph2D::AddWorkItem(
|
||||||
if (work_queue_ == nullptr) {
|
if (work_queue_ == nullptr) {
|
||||||
if (work_item() == WorkItem::Result::kRunOptimization) {
|
if (work_item() == WorkItem::Result::kRunOptimization) {
|
||||||
work_queue_ = common::make_unique<WorkQueue>();
|
work_queue_ = common::make_unique<WorkQueue>();
|
||||||
constraint_builder_.WhenDone(std::bind(&PoseGraph2D::HandleWorkQueue,
|
constraint_builder_.WhenDone(
|
||||||
this, std::placeholders::_1));
|
[this](const constraints::ConstraintBuilder2D::Result& result) {
|
||||||
|
HandleWorkQueue(result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const auto now = std::chrono::steady_clock::now();
|
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();
|
LOG(INFO) << "Remaining work items in queue: " << work_queue_->size();
|
||||||
// We have to optimize again.
|
// We have to optimize again.
|
||||||
constraint_builder_.WhenDone(
|
constraint_builder_.WhenDone(
|
||||||
std::bind(&PoseGraph2D::HandleWorkQueue, this, std::placeholders::_1));
|
[this](const constraints::ConstraintBuilder2D::Result& result) {
|
||||||
|
HandleWorkQueue(result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoseGraph2D::WaitForAllComputations() {
|
void PoseGraph2D::WaitForAllComputations() {
|
||||||
|
|
|
@ -152,7 +152,9 @@ void PoseGraph3D::AddWorkItem(
|
||||||
} else if (work_item() == WorkItem::Result::kRunOptimization) {
|
} else if (work_item() == WorkItem::Result::kRunOptimization) {
|
||||||
work_queue_ = common::make_unique<WorkQueue>();
|
work_queue_ = common::make_unique<WorkQueue>();
|
||||||
constraint_builder_.WhenDone(
|
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();
|
LOG(INFO) << "Remaining work items in queue: " << work_queue_->size();
|
||||||
// We have to optimize again.
|
// We have to optimize again.
|
||||||
constraint_builder_.WhenDone(
|
constraint_builder_.WhenDone(
|
||||||
std::bind(&PoseGraph3D::HandleWorkQueue, this, std::placeholders::_1));
|
[this](const constraints::ConstraintBuilder3D::Result& result) {
|
||||||
|
HandleWorkQueue(result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoseGraph3D::WaitForAllComputations() {
|
void PoseGraph3D::WaitForAllComputations() {
|
||||||
|
|
|
@ -60,7 +60,9 @@ TEST_F(ConstraintBuilder2DTest, CallsBack) {
|
||||||
EXPECT_CALL(mock_, Run(::testing::IsEmpty()));
|
EXPECT_CALL(mock_, Run(::testing::IsEmpty()));
|
||||||
constraint_builder_->NotifyEndOfNode();
|
constraint_builder_->NotifyEndOfNode();
|
||||||
constraint_builder_->WhenDone(
|
constraint_builder_->WhenDone(
|
||||||
std::bind(&MockCallback::Run, &mock_, std::placeholders::_1));
|
[this](const constraints::ConstraintBuilder2D::Result& result) {
|
||||||
|
mock_.Run(result);
|
||||||
|
});
|
||||||
thread_pool_.WaitUntilIdle();
|
thread_pool_.WaitUntilIdle();
|
||||||
EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), 1);
|
EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), 1);
|
||||||
}
|
}
|
||||||
|
@ -98,7 +100,9 @@ TEST_F(ConstraintBuilder2DTest, FindsConstraints) {
|
||||||
&PoseGraphInterface::Constraint::tag,
|
&PoseGraphInterface::Constraint::tag,
|
||||||
PoseGraphInterface::Constraint::INTER_SUBMAP)))));
|
PoseGraphInterface::Constraint::INTER_SUBMAP)))));
|
||||||
constraint_builder_->WhenDone(
|
constraint_builder_->WhenDone(
|
||||||
std::bind(&MockCallback::Run, &mock_, std::placeholders::_1));
|
[this](const constraints::ConstraintBuilder2D::Result& result) {
|
||||||
|
mock_.Run(result);
|
||||||
|
});
|
||||||
thread_pool_.WaitUntilIdle();
|
thread_pool_.WaitUntilIdle();
|
||||||
constraint_builder_->DeleteScanMatcher(submap_id);
|
constraint_builder_->DeleteScanMatcher(submap_id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,9 @@ TEST_F(ConstraintBuilder3DTest, CallsBack) {
|
||||||
EXPECT_CALL(mock_, Run(::testing::IsEmpty()));
|
EXPECT_CALL(mock_, Run(::testing::IsEmpty()));
|
||||||
constraint_builder_->NotifyEndOfNode();
|
constraint_builder_->NotifyEndOfNode();
|
||||||
constraint_builder_->WhenDone(
|
constraint_builder_->WhenDone(
|
||||||
std::bind(&MockCallback::Run, &mock_, std::placeholders::_1));
|
[this](const constraints::ConstraintBuilder3D::Result& result) {
|
||||||
|
mock_.Run(result);
|
||||||
|
});
|
||||||
thread_pool_.WaitUntilIdle();
|
thread_pool_.WaitUntilIdle();
|
||||||
EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), 1);
|
EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), 1);
|
||||||
}
|
}
|
||||||
|
@ -108,7 +110,9 @@ TEST_F(ConstraintBuilder3DTest, FindsConstraints) {
|
||||||
&PoseGraphInterface::Constraint::tag,
|
&PoseGraphInterface::Constraint::tag,
|
||||||
PoseGraphInterface::Constraint::INTER_SUBMAP)))));
|
PoseGraphInterface::Constraint::INTER_SUBMAP)))));
|
||||||
constraint_builder_->WhenDone(
|
constraint_builder_->WhenDone(
|
||||||
std::bind(&MockCallback::Run, &mock_, std::placeholders::_1));
|
[this](const constraints::ConstraintBuilder3D::Result& result) {
|
||||||
|
mock_.Run(result);
|
||||||
|
});
|
||||||
thread_pool_.WaitUntilIdle();
|
thread_pool_.WaitUntilIdle();
|
||||||
constraint_builder_->DeleteScanMatcher(submap_id);
|
constraint_builder_->DeleteScanMatcher(submap_id);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue