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/daemon/face/face-system.cpp b/daemon/face/face-system.cpp
index 5601057..79cb436 100644
--- a/daemon/face/face-system.cpp
+++ b/daemon/face/face-system.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,
@@ -94,7 +94,9 @@
void
FaceSystem::setConfigFile(ConfigFile& configFile)
{
- configFile.addSectionHandler(CFGSEC_FACESYSTEM, bind(&FaceSystem::processConfig, this, _1, _2, _3));
+ configFile.addSectionHandler(CFGSEC_FACESYSTEM, [this] (auto&&... args) {
+ processConfig(std::forward<decltype(args)>(args)...);
+ });
}
void
diff --git a/daemon/face/generic-link-service.cpp b/daemon/face/generic-link-service.cpp
index 819a91a..5ed4ac2 100644
--- a/daemon/face/generic-link-service.cpp
+++ b/daemon/face/generic-link-service.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2020, 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,
@@ -45,11 +45,11 @@
, m_reassembler(m_options.reassemblerOptions, this)
, m_reliability(m_options.reliabilityOptions, this)
, m_lastSeqNo(-2)
- , m_nextMarkTime(time::steady_clock::TimePoint::max())
+ , m_nextMarkTime(time::steady_clock::time_point::max())
, m_nMarkedSinceInMarkingState(0)
{
- m_reassembler.beforeTimeout.connect([this] (auto...) { ++this->nReassemblyTimeouts; });
- m_reliability.onDroppedInterest.connect([this] (const auto& i) { this->notifyDroppedInterest(i); });
+ m_reassembler.beforeTimeout.connect([this] (auto&&...) { ++nReassemblyTimeouts; });
+ m_reliability.onDroppedInterest.connect([this] (const auto& i) { notifyDroppedInterest(i); });
nReassembling.observe(&m_reassembler);
}
@@ -105,7 +105,7 @@
auto block = pkt.wireEncode();
if (mtu != MTU_UNLIMITED && block.size() > static_cast<size_t>(mtu)) {
- ++this->nOutOverMtu;
+ ++nOutOverMtu;
NFD_LOG_FACE_WARN("attempted to send packet over MTU limit");
return;
}
@@ -207,7 +207,7 @@
std::tie(isOk, frags) = m_fragmenter.fragmentPacket(pkt, mtu);
if (!isOk) {
// fragmentation failed (warning is logged by LpFragmenter)
- ++this->nFragmentationErrors;
+ ++nFragmentationErrors;
return;
}
}
@@ -261,7 +261,7 @@
if (static_cast<size_t>(sendQueueLength) > m_options.defaultCongestionThreshold) {
const auto now = time::steady_clock::now();
- if (m_nextMarkTime == time::steady_clock::TimePoint::max()) {
+ if (m_nextMarkTime == time::steady_clock::time_point::max()) {
m_nextMarkTime = now + m_options.baseCongestionMarkingInterval;
}
// Mark packet if sendQueue stays above target for one interval
@@ -279,10 +279,10 @@
m_nextMarkTime += interval;
}
}
- else if (m_nextMarkTime != time::steady_clock::TimePoint::max()) {
+ else if (m_nextMarkTime != time::steady_clock::time_point::max()) {
// Congestion incident has ended, so reset
NFD_LOG_FACE_DEBUG("Send queue length dropped below congestion threshold");
- m_nextMarkTime = time::steady_clock::TimePoint::max();
+ m_nextMarkTime = time::steady_clock::time_point::max();
m_nMarkedSinceInMarkingState = 0;
}
}
@@ -296,7 +296,7 @@
if (m_options.reliabilityOptions.isEnabled) {
if (!m_reliability.processIncomingPacket(pkt)) {
NFD_LOG_FACE_TRACE("received duplicate fragment: DROP");
- ++this->nDuplicateSequence;
+ ++nDuplicateSequence;
return;
}
}
@@ -321,7 +321,7 @@
}
}
catch (const tlv::Error& e) {
- ++this->nInLpInvalid;
+ ++nInLpInvalid;
NFD_LOG_FACE_WARN("packet parse error (" << e.what() << "): DROP");
}
}
@@ -344,13 +344,13 @@
this->decodeData(netPkt, firstPkt, endpointId);
break;
default:
- ++this->nInNetInvalid;
+ ++nInNetInvalid;
NFD_LOG_FACE_WARN("unrecognized network-layer packet TLV-TYPE " << netPkt.type() << ": DROP");
return;
}
}
catch (const tlv::Error& e) {
- ++this->nInNetInvalid;
+ ++nInNetInvalid;
NFD_LOG_FACE_WARN("packet parse error (" << e.what() << "): DROP");
}
}
@@ -376,7 +376,7 @@
}
if (firstPkt.has<lp::CachePolicyField>()) {
- ++this->nInNetInvalid;
+ ++nInNetInvalid;
NFD_LOG_FACE_WARN("received CachePolicy with Interest: DROP");
return;
}
@@ -399,7 +399,7 @@
}
if (firstPkt.has<lp::PrefixAnnouncementField>()) {
- ++this->nInNetInvalid;
+ ++nInNetInvalid;
NFD_LOG_FACE_WARN("received PrefixAnnouncement with Interest: DROP");
return;
}
@@ -421,13 +421,13 @@
auto data = make_shared<Data>(netPkt);
if (firstPkt.has<lp::NackField>()) {
- ++this->nInNetInvalid;
+ ++nInNetInvalid;
NFD_LOG_FACE_WARN("received Nack with Data: DROP");
return;
}
if (firstPkt.has<lp::NextHopFaceIdField>()) {
- ++this->nInNetInvalid;
+ ++nInNetInvalid;
NFD_LOG_FACE_WARN("received NextHopFaceId with Data: DROP");
return;
}
@@ -448,7 +448,7 @@
}
if (firstPkt.has<lp::NonDiscoveryField>()) {
- ++this->nInNetInvalid;
+ ++nInNetInvalid;
NFD_LOG_FACE_WARN("received NonDiscovery with Data: DROP");
return;
}
@@ -476,13 +476,13 @@
nack.setHeader(firstPkt.get<lp::NackField>());
if (firstPkt.has<lp::NextHopFaceIdField>()) {
- ++this->nInNetInvalid;
+ ++nInNetInvalid;
NFD_LOG_FACE_WARN("received NextHopFaceId with Nack: DROP");
return;
}
if (firstPkt.has<lp::CachePolicyField>()) {
- ++this->nInNetInvalid;
+ ++nInNetInvalid;
NFD_LOG_FACE_WARN("received CachePolicy with Nack: DROP");
return;
}
@@ -496,13 +496,13 @@
}
if (firstPkt.has<lp::NonDiscoveryField>()) {
- ++this->nInNetInvalid;
+ ++nInNetInvalid;
NFD_LOG_FACE_WARN("received NonDiscovery with Nack: DROP");
return;
}
if (firstPkt.has<lp::PrefixAnnouncementField>()) {
- ++this->nInNetInvalid;
+ ++nInNetInvalid;
NFD_LOG_FACE_WARN("received PrefixAnnouncement with Nack: DROP");
return;
}
diff --git a/daemon/face/network-predicate.cpp b/daemon/face/network-predicate.cpp
index 31a2cf8..07de63c 100644
--- a/daemon/face/network-predicate.cpp
+++ b/daemon/face/network-predicate.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,
@@ -198,8 +198,10 @@
bool
NetworkInterfacePredicate::operator()(const ndn::net::NetworkInterface& netif) const
{
- return std::any_of(m_whitelist.begin(), m_whitelist.end(), bind(&doesNetifMatchRule, std::cref(netif), _1)) &&
- std::none_of(m_blacklist.begin(), m_blacklist.end(), bind(&doesNetifMatchRule, std::cref(netif), _1));
+ return std::any_of(m_whitelist.begin(), m_whitelist.end(),
+ [&netif] (const auto& rule) { return doesNetifMatchRule(netif, rule); }) &&
+ std::none_of(m_blacklist.begin(), m_blacklist.end(),
+ [&netif] (const auto& rule) { return doesNetifMatchRule(netif, rule); });
}
static bool
@@ -219,8 +221,10 @@
bool
IpAddressPredicate::operator()(const boost::asio::ip::address& address) const
{
- return std::any_of(m_whitelist.begin(), m_whitelist.end(), bind(&doesAddressMatchRule, std::cref(address), _1)) &&
- std::none_of(m_blacklist.begin(), m_blacklist.end(), bind(&doesAddressMatchRule, std::cref(address), _1));
+ return std::any_of(m_whitelist.begin(), m_whitelist.end(),
+ [&address] (const auto& rule) { return doesAddressMatchRule(address, rule); }) &&
+ std::none_of(m_blacklist.begin(), m_blacklist.end(),
+ [&address] (const auto& rule) { return doesAddressMatchRule(address, rule); });
}
} // namespace face
diff --git a/daemon/face/tcp-factory.cpp b/daemon/face/tcp-factory.cpp
index f45d786..89e34d5 100644
--- a/daemon/face/tcp-factory.cpp
+++ b/daemon/face/tcp-factory.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,
@@ -200,8 +200,9 @@
if (it != m_channels.end())
return it->second;
- auto channel = make_shared<TcpChannel>(endpoint, m_wantCongestionMarking,
- bind(&TcpFactory::determineFaceScopeFromAddresses, this, _1, _2));
+ auto channel = make_shared<TcpChannel>(endpoint, m_wantCongestionMarking, [this] (auto&&... args) {
+ return determineFaceScopeFromAddresses(std::forward<decltype(args)>(args)...);
+ });
m_channels[endpoint] = channel;
return channel;
}
diff --git a/daemon/face/udp-factory.cpp b/daemon/face/udp-factory.cpp
index 9eabd42..8f7f77c 100644
--- a/daemon/face/udp-factory.cpp
+++ b/daemon/face/udp-factory.cpp
@@ -434,7 +434,7 @@
NFD_LOG_DEBUG("Not creating multicast faces on " << netif->getName() << ": no viable IP address");
// keep an eye on new addresses
m_netifConns[netif->getIndex()].addrAddConn =
- netif->onAddressAdded.connect([=] (auto...) { this->applyMcastConfigToNetif(netif); });
+ netif->onAddressAdded.connect([=] (auto&&...) { this->applyMcastConfigToNetif(netif); });
return {};
}
diff --git a/daemon/face/websocket-channel.cpp b/daemon/face/websocket-channel.cpp
index 13f6f38..957c9ad 100644
--- a/daemon/face/websocket-channel.cpp
+++ b/daemon/face/websocket-channel.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2020, 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,
@@ -53,13 +53,13 @@
}
return websocketpp::lib::error_code{};
});
- m_server.set_open_handler(bind(&WebSocketChannel::handleOpen, this, _1));
- m_server.set_close_handler(bind(&WebSocketChannel::handleClose, this, _1));
- m_server.set_message_handler(bind(&WebSocketChannel::handleMessage, this, _1, _2));
+ m_server.set_open_handler(std::bind(&WebSocketChannel::handleOpen, this, _1));
+ m_server.set_close_handler(std::bind(&WebSocketChannel::handleClose, this, _1));
+ m_server.set_message_handler(std::bind(&WebSocketChannel::handleMessage, this, _1, _2));
// Detect disconnections using ping-pong messages
- m_server.set_pong_handler(bind(&WebSocketChannel::handlePong, this, _1));
- m_server.set_pong_timeout_handler(bind(&WebSocketChannel::handlePongTimeout, this, _1));
+ m_server.set_pong_handler(std::bind(&WebSocketChannel::handlePong, this, _1));
+ m_server.set_pong_timeout_handler(std::bind(&WebSocketChannel::handlePongTimeout, this, _1));
// Always set SO_REUSEADDR flag
m_server.set_reuse_addr(true);