Reduce usage of std::bind()
C++14 lambdas are easier to read, easier to debug,
and can usually be better optimized by the compiler.
Change-Id: I294f275904f91942a8de946fe63e77078a7608a6
diff --git a/tools/nfd-autoreg.cpp b/tools/nfd-autoreg.cpp
index fed9cfb..3745cb0 100644
--- a/tools/nfd-autoreg.cpp
+++ b/tools/nfd-autoreg.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2021, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -90,7 +90,7 @@
isBlacklisted(const boost::asio::ip::address& address) const
{
return std::any_of(m_blackList.begin(), m_blackList.end(),
- bind(&Network::doesContain, _1, address));
+ std::bind(&Network::doesContain, _1, address));
}
/**
@@ -100,7 +100,7 @@
isWhitelisted(const boost::asio::ip::address& address) const
{
return std::any_of(m_whiteList.begin(), m_whiteList.end(),
- bind(&Network::doesContain, _1, address));
+ std::bind(&Network::doesContain, _1, address));
}
void
@@ -114,8 +114,8 @@
.setOrigin(nfd::ROUTE_ORIGIN_AUTOREG)
.setCost(m_cost)
.setExpirationPeriod(time::milliseconds::max()),
- bind(&AutoregServer::onRegisterCommandSuccess, this, faceId, prefix),
- bind(&AutoregServer::onRegisterCommandFailure, this, faceId, prefix, _1));
+ std::bind(&AutoregServer::onRegisterCommandSuccess, this, faceId, prefix),
+ std::bind(&AutoregServer::onRegisterCommandFailure, this, faceId, prefix, _1));
}
}
@@ -154,12 +154,6 @@
}
}
- void
- signalHandler()
- {
- m_face.shutdown();
- }
-
static void
usage(std::ostream& os,
const boost::program_options::options_description& desc,
@@ -194,11 +188,11 @@
std::cout << " " << network << std::endl;
}
- m_faceMonitor.onNotification.connect(bind(&AutoregServer::onNotification, this, _1));
+ m_faceMonitor.onNotification.connect(std::bind(&AutoregServer::onNotification, this, _1));
m_faceMonitor.start();
boost::asio::signal_set signalSet(m_face.getIoService(), SIGINT, SIGTERM);
- signalSet.async_wait(bind(&AutoregServer::signalHandler, this));
+ signalSet.async_wait([this] (auto&&...) { m_face.shutdown(); });
m_face.processEvents();
}
@@ -207,13 +201,13 @@
startFetchingFaceStatusDataset()
{
m_controller.fetch<nfd::FaceDataset>(
- [this] (const std::vector<nfd::FaceStatus>& faces) {
+ [this] (const auto& faces) {
for (const auto& faceStatus : faces) {
registerPrefixesIfNeeded(faceStatus.getFaceId(), FaceUri(faceStatus.getRemoteUri()),
faceStatus.getFacePersistency());
}
},
- [] (uint32_t code, const std::string& reason) {});
+ [] (auto&&...) {});
}
int