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/rib/rib-entry.cpp b/daemon/rib/rib-entry.cpp
index 7385d16..6acae09 100644
--- a/daemon/rib/rib-entry.cpp
+++ b/daemon/rib/rib-entry.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,
@@ -33,22 +33,30 @@
NFD_LOG_INIT(RibEntry);
+static bool
+compareFaceIdAndOrigin(const Route& lhs, const Route& rhs)
+{
+ return lhs.faceId == rhs.faceId && lhs.origin == rhs.origin;
+}
+
RibEntry::RouteList::iterator
RibEntry::findRoute(const Route& route)
{
- return std::find_if(begin(), end(), bind(&compareFaceIdAndOrigin, _1, route));
+ return std::find_if(begin(), end(),
+ [&] (const auto& r) { return compareFaceIdAndOrigin(r, route); });
}
RibEntry::RouteList::const_iterator
RibEntry::findRoute(const Route& route) const
{
- return std::find_if(begin(), end(), bind(&compareFaceIdAndOrigin, _1, route));
+ return std::find_if(begin(), end(),
+ [&] (const auto& r) { return compareFaceIdAndOrigin(r, route); });
}
std::pair<RibEntry::iterator, bool>
RibEntry::insertRoute(const Route& route)
{
- iterator it = findRoute(route);
+ auto it = findRoute(route);
if (it == end()) {
if (route.flags & ndn::nfd::ROUTE_FLAG_CAPTURE) {
@@ -65,23 +73,21 @@
void
RibEntry::eraseRoute(const Route& route)
{
- RibEntry::iterator it = findRoute(route);
+ auto it = findRoute(route);
eraseRoute(it);
}
bool
RibEntry::hasRoute(const Route& route)
{
- RibEntry::const_iterator it = findRoute(route);
-
+ auto it = findRoute(route);
return it != end();
}
bool
-RibEntry::hasFaceId(const uint64_t faceId) const
+RibEntry::hasFaceId(uint64_t faceId) const
{
- RibEntry::const_iterator it = std::find_if(begin(), end(), bind(&compareFaceId, _1, faceId));
-
+ auto it = std::find_if(begin(), end(), [faceId] (const auto& r) { return r.faceId == faceId; });
return it != end();
}
@@ -134,14 +140,14 @@
void
RibEntry::removeInheritedRoute(const Route& route)
{
- m_inheritedRoutes.remove_if(bind(&compareFaceId, _1, route.faceId));
+ m_inheritedRoutes.remove_if([id = route.faceId] (const auto& r) { return r.faceId == id; });
}
RibEntry::RouteList::const_iterator
RibEntry::findInheritedRoute(const Route& route) const
{
return std::find_if(m_inheritedRoutes.begin(), m_inheritedRoutes.end(),
- bind(&compareFaceId, _1, route.faceId));
+ [id = route.faceId] (const auto& r) { return r.faceId == id; });
}
bool
@@ -243,7 +249,7 @@
time::milliseconds maxExpiration) const
{
const Route* bestAnnRoute = nullptr;
- auto entryExpiry = time::steady_clock::TimePoint::min();
+ auto entryExpiry = time::steady_clock::time_point::min();
for (const Route& route : *this) {
if (route.expires) {
@@ -255,7 +261,7 @@
}
}
else {
- entryExpiry = time::steady_clock::TimePoint::max();
+ entryExpiry = time::steady_clock::time_point::max();
}
}