common: stop importing std::{bind,ref,cref} into namespace ndn
And reduce the usage of std::bind() throughout the codebase.
C++14 lambdas are easier to understand for humans and more
likely to be optimized by the compiler.
Change-Id: Ia59fad34539710f8801c52914896ce426fb7e538
diff --git a/tests/unit/face.t.cpp b/tests/unit/face.t.cpp
index f7c6132..eaab9b6 100644
--- a/tests/unit/face.t.cpp
+++ b/tests/unit/face.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -35,6 +35,7 @@
namespace tests {
using ndn::util::DummyClientFace;
+using std::bind;
struct WantPrefixRegReply;
struct NoPrefixRegReply;
diff --git a/tests/unit/mgmt/dispatcher.t.cpp b/tests/unit/mgmt/dispatcher.t.cpp
index a6054c2..7827516 100644
--- a/tests/unit/mgmt/dispatcher.t.cpp
+++ b/tests/unit/mgmt/dispatcher.t.cpp
@@ -31,6 +31,7 @@
namespace tests {
using namespace ndn::tests;
+using std::bind;
class DispatcherFixture : public IoKeyChainFixture
{
diff --git a/tests/unit/mgmt/nfd/controller-fixture.hpp b/tests/unit/mgmt/nfd/controller-fixture.hpp
index 77c7620..764ff41 100644
--- a/tests/unit/mgmt/nfd/controller-fixture.hpp
+++ b/tests/unit/mgmt/nfd/controller-fixture.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -42,8 +42,8 @@
: face(m_io, m_keyChain)
, m_validator(true)
, controller(face, m_keyChain, m_validator)
- , commandFailCallback(bind(&ControllerFixture::recordCommandFail, this, _1))
- , datasetFailCallback(bind(&ControllerFixture::recordDatasetFail, this, _1, _2))
+ , commandFailCallback([this] (const auto& resp) { failCodes.push_back(resp.getCode()); })
+ , datasetFailCallback([this] (auto code, const auto&) { failCodes.push_back(code); })
{
m_keyChain.setDefaultIdentity(m_keyChain.createIdentity("/localhost/ControllerFixture"));
}
@@ -59,19 +59,6 @@
m_validator.getPolicy().setResult(shouldAccept);
}
-private:
- void
- recordCommandFail(const ControlResponse& response)
- {
- failCodes.push_back(response.getCode());
- }
-
- void
- recordDatasetFail(uint32_t code, const std::string& reason)
- {
- failCodes.push_back(code);
- }
-
protected:
ndn::util::DummyClientFace face;
DummyValidator m_validator;
diff --git a/tests/unit/mgmt/nfd/controller.t.cpp b/tests/unit/mgmt/nfd/controller.t.cpp
index b0a5838..83deb23 100644
--- a/tests/unit/mgmt/nfd/controller.t.cpp
+++ b/tests/unit/mgmt/nfd/controller.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -37,11 +37,6 @@
class CommandFixture : public ControllerFixture
{
protected:
- CommandFixture()
- : succeedCallback(bind(&CommandFixture::succeed, this, _1))
- {
- }
-
void
respond(const ControlResponse& responsePayload)
{
@@ -51,15 +46,10 @@
this->advanceClocks(1_ms);
}
-private:
- void
- succeed(const ControlParameters& parameters)
- {
- succeeds.push_back(parameters);
- }
-
protected:
- Controller::CommandSucceedCallback succeedCallback;
+ Controller::CommandSucceedCallback succeedCallback = [this] (const auto& params) {
+ succeeds.push_back(params);
+ };
std::vector<ControlParameters> succeeds;
};
diff --git a/tests/unit/mgmt/status-dataset-context.t.cpp b/tests/unit/mgmt/status-dataset-context.t.cpp
index 58c8382..6d1e0b9 100644
--- a/tests/unit/mgmt/status-dataset-context.t.cpp
+++ b/tests/unit/mgmt/status-dataset-context.t.cpp
@@ -229,13 +229,7 @@
class AbnormalStateTestFixture
{
protected:
- AbnormalStateTestFixture()
- : context(Interest("/abnormal-state"), bind([]{}), bind([]{}))
- {
- }
-
-protected:
- StatusDatasetContext context;
+ StatusDatasetContext context{Interest("/abnormal-state"), [] (auto&&...) {}, [] (auto&&...) {}};
};
BOOST_FIXTURE_TEST_SUITE(AbnormalState, AbnormalStateTestFixture)
diff --git a/tests/unit/net/dns.t.cpp b/tests/unit/net/dns.t.cpp
index db834c0..374eeea 100644
--- a/tests/unit/net/dns.t.cpp
+++ b/tests/unit/net/dns.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -36,12 +36,6 @@
class DnsFixture
{
public:
- DnsFixture()
- : m_nFailures(0)
- , m_nSuccesses(0)
- {
- }
-
void
onSuccess(const IpAddress& resolvedAddress,
const IpAddress& expectedAddress,
@@ -51,7 +45,7 @@
++m_nSuccesses;
if (!isValid) {
- BOOST_FAIL("Resolved to " + resolvedAddress.to_string() + ", but should have failed");
+ BOOST_ERROR("Resolved to " + resolvedAddress.to_string() + ", but should have failed");
}
BOOST_CHECK_EQUAL(resolvedAddress.is_v4(), expectedAddress.is_v4());
@@ -64,20 +58,15 @@
}
void
- onFailure(bool isValid)
+ onFailure(bool shouldFail)
{
++m_nFailures;
-
- if (!isValid) {
- BOOST_FAIL("Resolution should not have failed");
- }
-
- BOOST_CHECK_MESSAGE(true, "Resolution failed as expected");
+ BOOST_CHECK_MESSAGE(shouldFail, "Resolution should not have failed");
}
protected:
- uint32_t m_nFailures;
- uint32_t m_nSuccesses;
+ int m_nFailures = 0;
+ int m_nSuccesses = 0;
boost::asio::io_service m_ioService;
};
@@ -89,8 +78,8 @@
SKIP_IF_IP_UNAVAILABLE();
asyncResolve("nothost.nothost.nothost.arpa",
- bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v4()), false, false),
- bind(&DnsFixture::onFailure, this, true),
+ std::bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v4()), false, false),
+ [this] (auto&&...) { onFailure(true); },
m_ioService); // should fail
m_ioService.run();
@@ -103,9 +92,9 @@
SKIP_IF_IPV4_UNAVAILABLE();
asyncResolve("192.0.2.1",
- bind(&DnsFixture::onSuccess, this, _1,
- IpAddress(address_v4::from_string("192.0.2.1")), true, true),
- bind(&DnsFixture::onFailure, this, false),
+ std::bind(&DnsFixture::onSuccess, this, _1,
+ IpAddress(address_v4::from_string("192.0.2.1")), true, true),
+ [this] (auto&&...) { onFailure(false); },
m_ioService);
m_ioService.run();
@@ -118,15 +107,15 @@
SKIP_IF_IPV6_UNAVAILABLE();
asyncResolve("ipv6.google.com", // only IPv6 address should be available
- bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v6()), true, false),
- bind(&DnsFixture::onFailure, this, false),
+ std::bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v6()), true, false),
+ [this] (auto&&...) { onFailure(false); },
m_ioService);
asyncResolve("2001:db8:3f9:0:3025:ccc5:eeeb:86d3",
- bind(&DnsFixture::onSuccess, this, _1,
- IpAddress(address_v6::from_string("2001:db8:3f9:0:3025:ccc5:eeeb:86d3")),
- true, true),
- bind(&DnsFixture::onFailure, this, false),
+ std::bind(&DnsFixture::onSuccess, this, _1,
+ IpAddress(address_v6::from_string("2001:db8:3f9:0:3025:ccc5:eeeb:86d3")),
+ true, true),
+ [this] (auto&&...) { onFailure(false); },
m_ioService);
m_ioService.run();
@@ -140,28 +129,28 @@
SKIP_IF_IPV6_UNAVAILABLE();
asyncResolve("www.named-data.net",
- bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v4()), true, false),
- bind(&DnsFixture::onFailure, this, false),
+ std::bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v4()), true, false),
+ [this] (auto&&...) { onFailure(false); },
m_ioService, Ipv4Only());
asyncResolve("a.root-servers.net",
- bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v4()), true, false),
- bind(&DnsFixture::onFailure, this, false),
+ std::bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v4()), true, false),
+ [this] (auto&&...) { onFailure(false); },
m_ioService, Ipv4Only()); // request IPv4 address
asyncResolve("a.root-servers.net",
- bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v6()), true, false),
- bind(&DnsFixture::onFailure, this, false),
+ std::bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v6()), true, false),
+ [this] (auto&&...) { onFailure(false); },
m_ioService, Ipv6Only()); // request IPv6 address
asyncResolve("ipv6.google.com", // only IPv6 address should be available
- bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v6()), true, false),
- bind(&DnsFixture::onFailure, this, false),
+ std::bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v6()), true, false),
+ [this] (auto&&...) { onFailure(false); },
m_ioService, Ipv6Only());
asyncResolve("ipv6.google.com", // only IPv6 address should be available
- bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v6()), false, false),
- bind(&DnsFixture::onFailure, this, true),
+ std::bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v6()), false, false),
+ [this] (auto&&...) { onFailure(true); },
m_ioService, Ipv4Only()); // should fail
m_ioService.run();
diff --git a/tests/unit/net/face-uri.t.cpp b/tests/unit/net/face-uri.t.cpp
index c8f7d16..76af381 100644
--- a/tests/unit/net/face-uri.t.cpp
+++ b/tests/unit/net/face-uri.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California,
+ * Copyright (c) 2013-2021 Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -69,8 +69,8 @@
auto tc = make_shared<CanonizeTestCase>(request, shouldSucceed, expectedUri);
FaceUri uri(request);
- uri.canonize(bind(&CanonizeFixture::onCanonizeSuccess, this, tc, _1),
- bind(&CanonizeFixture::onCanonizeFailure, this, tc, _1),
+ uri.canonize(std::bind(&CanonizeFixture::onCanonizeSuccess, this, tc, _1),
+ std::bind(&CanonizeFixture::onCanonizeFailure, this, tc, _1),
m_io, 10_s);
}
diff --git a/tests/unit/security/certificate-fetcher-from-network.t.cpp b/tests/unit/security/certificate-fetcher-from-network.t.cpp
index caf941a..36a1ae9 100644
--- a/tests/unit/security/certificate-fetcher-from-network.t.cpp
+++ b/tests/unit/security/certificate-fetcher-from-network.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -65,7 +65,7 @@
interest.setCanBePrefix(false);
m_keyChain.sign(interest, signingByIdentity(subSubIdentity));
- processInterest = bind(&CertificateFetcherFromNetworkFixture<Response>::makeResponse, this, _1);
+ processInterest = [this] (const Interest& i) { makeResponse(i); };
}
void
diff --git a/tests/unit/security/validator-fixture.cpp b/tests/unit/security/validator-fixture.cpp
index 8bb4713..7a7ee14 100644
--- a/tests/unit/security/validator-fixture.cpp
+++ b/tests/unit/security/validator-fixture.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -46,7 +46,7 @@
{
util::signal::ScopedConnection conn = face.onSendInterest.connect([this] (const Interest& interest) {
if (processInterest) {
- m_io.post(bind(processInterest, interest));
+ m_io.post([=] { processInterest(interest); });
}
});
advanceClocks(s_mockPeriod, s_mockTimes);
diff --git a/tests/unit/security/validator-null.t.cpp b/tests/unit/security/validator-null.t.cpp
index 9d04cb8..8fc5a5e 100644
--- a/tests/unit/security/validator-null.t.cpp
+++ b/tests/unit/security/validator-null.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -28,6 +28,8 @@
namespace security {
namespace tests {
+using std::bind;
+
BOOST_AUTO_TEST_SUITE(Security)
BOOST_FIXTURE_TEST_SUITE(TestValidatorNull, ndn::tests::KeyChainFixture)
diff --git a/tests/unit/util/notification-subscriber.t.cpp b/tests/unit/util/notification-subscriber.t.cpp
index d8f9dfd..3936e9e 100644
--- a/tests/unit/util/notification-subscriber.t.cpp
+++ b/tests/unit/util/notification-subscriber.t.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,
@@ -74,45 +74,16 @@
void
deliverNack(const Interest& interest, const lp::NackReason& reason)
{
- lp::Nack nack = makeNack(interest, reason);
- subscriberFace.receive(nack);
- }
-
- void
- afterNotification(const SimpleNotification& notification)
- {
- lastNotification = notification;
- }
-
- void
- afterNack(const lp::Nack& nack)
- {
- lastNack = nack;
- }
-
- void
- afterTimeout()
- {
- hasTimeout = true;
- }
-
- void
- afterDecodeError(const Data& data)
- {
- lastDecodeErrorData = data;
+ subscriberFace.receive(makeNack(interest, reason));
}
void
connectHandlers()
{
- notificationConn = subscriber.onNotification.connect(
- bind(&NotificationSubscriberFixture::afterNotification, this, _1));
- nackConn = subscriber.onNack.connect(
- bind(&NotificationSubscriberFixture::afterNack, this, _1));
- subscriber.onTimeout.connect(
- bind(&NotificationSubscriberFixture::afterTimeout, this));
- subscriber.onDecodeError.connect(
- bind(&NotificationSubscriberFixture::afterDecodeError, this, _1));
+ notificationConn = subscriber.onNotification.connect([this] (const auto& n) { lastNotification = n; });
+ nackConn = subscriber.onNack.connect([this] (const auto& nack) { lastNack = nack; });
+ subscriber.onTimeout.connect([this] { hasTimeout = true; });
+ subscriber.onDecodeError.connect([this] (const auto& data) { lastDecodeErrorData = data; });
}
void
diff --git a/tests/unit/util/scheduler.t.cpp b/tests/unit/util/scheduler.t.cpp
index 12f018a..1040b92 100644
--- a/tests/unit/util/scheduler.t.cpp
+++ b/tests/unit/util/scheduler.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -109,7 +109,7 @@
void
reschedule()
{
- EventId eventId = scheduler.schedule(100_ms, bind(&SelfRescheduleFixture::reschedule, this));
+ EventId eventId = scheduler.schedule(100_ms, [this] { reschedule(); });
selfEventId.cancel();
selfEventId = eventId;
@@ -125,7 +125,7 @@
selfEventId.cancel();
if (count < 5) {
- selfEventId = scheduler.schedule(100_ms, bind(&SelfRescheduleFixture::reschedule2, this));
+ selfEventId = scheduler.schedule(100_ms, [this] { reschedule2(); });
count++;
}
}
@@ -150,21 +150,21 @@
BOOST_FIXTURE_TEST_CASE(Reschedule, SelfRescheduleFixture)
{
- selfEventId = scheduler.schedule(0_s, bind(&SelfRescheduleFixture::reschedule, this));
+ selfEventId = scheduler.schedule(0_s, [this] { reschedule(); });
BOOST_REQUIRE_NO_THROW(advanceClocks(50_ms, 1000_ms));
BOOST_CHECK_EQUAL(count, 5);
}
BOOST_FIXTURE_TEST_CASE(Reschedule2, SelfRescheduleFixture)
{
- selfEventId = scheduler.schedule(0_s, bind(&SelfRescheduleFixture::reschedule2, this));
+ selfEventId = scheduler.schedule(0_s, [this] { reschedule2(); });
BOOST_REQUIRE_NO_THROW(advanceClocks(50_ms, 1000_ms));
BOOST_CHECK_EQUAL(count, 5);
}
BOOST_FIXTURE_TEST_CASE(Reschedule3, SelfRescheduleFixture)
{
- selfEventId = scheduler.schedule(0_s, bind(&SelfRescheduleFixture::reschedule3, this));
+ selfEventId = scheduler.schedule(0_s, [this] { reschedule3(); });
BOOST_REQUIRE_NO_THROW(advanceClocks(50_ms, 1000_ms));
BOOST_CHECK_EQUAL(count, 6);
}
diff --git a/tests/unit/util/segment-fetcher.t.cpp b/tests/unit/util/segment-fetcher.t.cpp
index c58c1f9..55247fe 100644
--- a/tests/unit/util/segment-fetcher.t.cpp
+++ b/tests/unit/util/segment-fetcher.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -36,6 +36,7 @@
namespace tests {
using namespace ndn::tests;
+using std::bind;
class SegmentFetcherFixture : public IoKeyChainFixture
{