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/tests/daemon/fw/access-strategy.t.cpp b/tests/daemon/fw/access-strategy.t.cpp
index afa73b6..cb55cca 100644
--- a/tests/daemon/fw/access-strategy.t.cpp
+++ b/tests/daemon/fw/access-strategy.t.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,
@@ -315,7 +315,7 @@
shared_ptr<Interest> interest1 = makeInterest("ndn:/laptops/A/1");
bool hasData1 = false;
consumer->getClientFace().expressInterest(*interest1,
- bind([&hasData1] { hasData1 = true; }),
+ [&] (auto&&...) { hasData1 = true; },
nullptr, nullptr);
this->advanceClocks(5_ms, 1_s);
BOOST_CHECK_EQUAL(hasData1, true);
@@ -324,9 +324,9 @@
shared_ptr<Interest> interest2a = makeInterest("ndn:/laptops/A/2");
bool hasData2a = false, hasTimeout2a = false;
consumer->getClientFace().expressInterest(*interest2a,
- bind([&hasData2a] { hasData2a = true; }),
+ [&] (auto&&...) { hasData2a = true; },
nullptr,
- bind([&hasTimeout2a] { hasTimeout2a = true; }));
+ [&] (auto&&...) { hasTimeout2a = true; });
producerA->fail();
this->advanceClocks(5_ms, 60_ms);
BOOST_CHECK_EQUAL(hasData2a, false);
@@ -336,7 +336,7 @@
shared_ptr<Interest> interest2b = makeInterest("ndn:/laptops/A/2");
bool hasData2b = false;
consumer->getClientFace().expressInterest(*interest2b,
- bind([&hasData2b] { hasData2b = true; }),
+ [&] (auto&&...) { hasData2b = true; },
nullptr, nullptr);
producerA->recover();
this->advanceClocks(5_ms, 1_s);
@@ -346,7 +346,7 @@
shared_ptr<Interest> interest2c = makeInterest("ndn:/laptops/A/2");
bool hasData2c = false;
consumer->getClientFace().expressInterest(*interest2c,
- bind([&hasData2c] { hasData2c = true; }),
+ [&] (auto&&...) { hasData2c = true; },
nullptr, nullptr);
this->advanceClocks(5_ms, 1_s);
BOOST_CHECK_EQUAL(hasData2c, true);
diff --git a/tests/daemon/fw/algorithm.t.cpp b/tests/daemon/fw/algorithm.t.cpp
index b998ec2..4a86d78 100644
--- a/tests/daemon/fw/algorithm.t.cpp
+++ b/tests/daemon/fw/algorithm.t.cpp
@@ -190,7 +190,7 @@
auto interest = makeInterest("ndn:/c1I7QCtc");
pit::Entry entry(*interest);
- time::steady_clock::TimePoint before = time::steady_clock::now();
+ auto before = time::steady_clock::now();
entry.insertOrUpdateOutRecord(*face1, *interest);
this->advanceClocks(1_s);
diff --git a/tests/daemon/fw/best-route-strategy.t.cpp b/tests/daemon/fw/best-route-strategy.t.cpp
index 5066cca..7293762 100644
--- a/tests/daemon/fw/best-route-strategy.t.cpp
+++ b/tests/daemon/fw/best-route-strategy.t.cpp
@@ -96,7 +96,7 @@
// more often than DEFAULT_MIN_RETX_INTERVAL
scheduler::EventId retxFrom4Evt;
size_t nSentLast = strategy.sendInterestHistory.size();
- time::steady_clock::TimePoint timeSentLast = time::steady_clock::now();
+ auto timeSentLast = time::steady_clock::now();
std::function<void()> periodicalRetxFrom4; // let periodicalRetxFrom4 lambda capture itself
periodicalRetxFrom4 = [&] {
pitEntry->insertOrUpdateInRecord(*face4, *interest);
diff --git a/tests/daemon/fw/forwarding-hint.t.cpp b/tests/daemon/fw/forwarding-hint.t.cpp
index fe3e51c..da63619 100644
--- a/tests/daemon/fw/forwarding-hint.t.cpp
+++ b/tests/daemon/fw/forwarding-hint.t.cpp
@@ -114,8 +114,8 @@
shared_ptr<TopologyLink> linkAH, linkHT, linkTP, linkHC, linkCS, linkSQ;
shared_ptr<TopologyAppLink> consumerA, producerP, producerQ;
- Delegation delTelia = {10, "/telia/terabits"};
- Delegation delUcla = {20, "/ucla/cs"};
+ ndn::Delegation delTelia = {10, "/telia/terabits"};
+ ndn::Delegation delUcla = {20, "/ucla/cs"};
};
BOOST_FIXTURE_TEST_SUITE(NdnsimTeliaUclaTopology, NdnsimTeliaUclaTopologyFixture)
@@ -128,12 +128,12 @@
// A forwards Interest according to default route, no change to forwarding hint
BOOST_CHECK_EQUAL(linkAH->getFace(nodeA).getCounters().nOutInterests, 1);
const Interest& interestAH = topo.getPcap(linkAH->getFace(nodeA)).sentInterests.at(0);
- BOOST_CHECK_EQUAL(interestAH.getForwardingHint(), DelegationList({delTelia, delUcla}));
+ BOOST_CHECK_EQUAL(interestAH.getForwardingHint(), ndn::DelegationList({delTelia, delUcla}));
// H prefers T, no change to forwarding hint
BOOST_CHECK_EQUAL(linkHT->getFace(nodeH).getCounters().nOutInterests, 1);
const Interest& interestHT = topo.getPcap(linkHT->getFace(nodeH)).sentInterests.at(0);
- BOOST_CHECK_EQUAL(interestHT.getForwardingHint(), DelegationList({delTelia, delUcla}));
+ BOOST_CHECK_EQUAL(interestHT.getForwardingHint(), ndn::DelegationList({delTelia, delUcla}));
// T forwards to P, forwarding hint stripped when Interest reaches producer region
BOOST_CHECK_EQUAL(linkTP->getFace(nodeT).getCounters().nOutInterests, 1);
@@ -157,17 +157,17 @@
// A forwards Interest according to default route, no change to forwarding hint
BOOST_CHECK_EQUAL(linkAH->getFace(nodeA).getCounters().nOutInterests, 1);
const Interest& interestAH = topo.getPcap(linkAH->getFace(nodeA)).sentInterests.at(0);
- BOOST_CHECK_EQUAL(interestAH.getForwardingHint(), DelegationList({delTelia, delUcla}));
+ BOOST_CHECK_EQUAL(interestAH.getForwardingHint(), ndn::DelegationList({delTelia, delUcla}));
// H forwards to C, no change to forwarding hint
BOOST_CHECK_EQUAL(linkHC->getFace(nodeH).getCounters().nOutInterests, 1);
const Interest& interestHC = topo.getPcap(linkHC->getFace(nodeH)).sentInterests.at(0);
- BOOST_CHECK_EQUAL(interestHC.getForwardingHint(), DelegationList({delTelia, delUcla}));
+ BOOST_CHECK_EQUAL(interestHC.getForwardingHint(), ndn::DelegationList({delTelia, delUcla}));
// C forwards to S, no change to forwarding hint
BOOST_CHECK_EQUAL(linkCS->getFace(nodeC).getCounters().nOutInterests, 1);
const Interest& interestCS = topo.getPcap(linkCS->getFace(nodeC)).sentInterests.at(0);
- BOOST_CHECK_EQUAL(interestCS.getForwardingHint(), DelegationList({delTelia, delUcla}));
+ BOOST_CHECK_EQUAL(interestCS.getForwardingHint(), ndn::DelegationList({delTelia, delUcla}));
// S forwards to Q, forwarding hint stripped when Interest reaches producer region
BOOST_CHECK_EQUAL(linkSQ->getFace(nodeS).getCounters().nOutInterests, 1);
diff --git a/tests/daemon/fw/multicast-strategy.t.cpp b/tests/daemon/fw/multicast-strategy.t.cpp
index 90e4b1e..a1656e5 100644
--- a/tests/daemon/fw/multicast-strategy.t.cpp
+++ b/tests/daemon/fw/multicast-strategy.t.cpp
@@ -176,7 +176,7 @@
// more often than DEFAULT_MIN_RETX_INTERVAL
scheduler::EventId retxFrom4Evt;
size_t nSentLast = strategy.sendInterestHistory.size();
- time::steady_clock::TimePoint timeSentLast = time::steady_clock::now();
+ auto timeSentLast = time::steady_clock::now();
std::function<void()> periodicalRetxFrom4; // let periodicalRetxFrom4 lambda capture itself
periodicalRetxFrom4 = [&] {
pitEntry->insertOrUpdateInRecord(*face3, *interest);
diff --git a/tests/daemon/fw/strategy-nack-return.t.cpp b/tests/daemon/fw/strategy-nack-return.t.cpp
index 9b5f588..73db46c 100644
--- a/tests/daemon/fw/strategy-nack-return.t.cpp
+++ b/tests/daemon/fw/strategy-nack-return.t.cpp
@@ -261,11 +261,11 @@
ndn::Face& appD = topo.addAppFace("D", nodeD)->getClientFace();
int nNacksA = 0, nNacksD = 0;
- appA.expressInterest(*makeInterest("/P/1"), nullptr, bind([&nNacksA] { ++nNacksA; }), nullptr);
- appD.expressInterest(*makeInterest("/P/1"), nullptr, bind([&nNacksD] { ++nNacksD; }), nullptr);
+ appA.expressInterest(*makeInterest("/P/1"), nullptr, [&] (auto&&...) { ++nNacksA; }, nullptr);
+ appD.expressInterest(*makeInterest("/P/1"), nullptr, [&] (auto&&...) { ++nNacksD; }, nullptr);
this->advanceClocks(1_ms, 5_ms);
- appA.expressInterest(*makeInterest("/P/1"), nullptr, bind([&nNacksA] { ++nNacksA; }), nullptr);
- appD.expressInterest(*makeInterest("/P/1"), nullptr, bind([&nNacksD] { ++nNacksD; }), nullptr);
+ appA.expressInterest(*makeInterest("/P/1"), nullptr, [&] (auto&&...) { ++nNacksA; }, nullptr);
+ appD.expressInterest(*makeInterest("/P/1"), nullptr, [&] (auto&&...) { ++nNacksD; }, nullptr);
this->advanceClocks(1_ms, 100_ms);
// As long as at least one Nack arrives at each client, strategy behavior is correct.
diff --git a/tests/daemon/fw/topology-tester.hpp b/tests/daemon/fw/topology-tester.hpp
index 6e5cb95..842e810 100644
--- a/tests/daemon/fw/topology-tester.hpp
+++ b/tests/daemon/fw/topology-tester.hpp
@@ -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,
@@ -242,7 +242,7 @@
/** \brief captured packet timestamp tag
*/
-using TopologyPcapTimestamp = ndn::SimpleTag<time::steady_clock::TimePoint, 0>;
+using TopologyPcapTimestamp = ndn::SimpleTag<time::steady_clock::time_point, 0>;
/** \brief builds a topology for forwarding tests
*/
diff --git a/tests/daemon/fw/unsolicited-data-policy.t.cpp b/tests/daemon/fw/unsolicited-data-policy.t.cpp
index bc95d4f..5c8c8ad 100644
--- a/tests/daemon/fw/unsolicited-data-policy.t.cpp
+++ b/tests/daemon/fw/unsolicited-data-policy.t.cpp
@@ -58,8 +58,8 @@
tribool isFound = indeterminate;
cs.find(Interest(data.getFullName()),
- bind([&] { isFound = true; }),
- bind([&] { isFound = false; }));
+ [&] (auto&&...) { isFound = true; },
+ [&] (auto&&...) { isFound = false; });
this->advanceClocks(1_ms);
BOOST_REQUIRE(!indeterminate(isFound));