Use more C++17 features
Mainly structured bindings, inline variables, and class template
argument deduction, plus many more smaller things.
Change-Id: I810d17e0adb470426e4e30c898e03b3140ad052f
diff --git a/tests/daemon/table/cs.t.cpp b/tests/daemon/table/cs.t.cpp
index 85886da..b8e34de 100644
--- a/tests/daemon/table/cs.t.cpp
+++ b/tests/daemon/table/cs.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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -264,12 +264,12 @@
insert(12, nameAB);
insert(4, nameD);
- std::set<Name> expected = {nameA, nameAB, nameABC, nameD};
+ const std::set<Name> expected{nameA, nameAB, nameABC, nameD};
std::set<Name> actual;
for (const auto& csEntry : cs) {
actual.insert(csEntry.getName());
}
- BOOST_CHECK_EQUAL_COLLECTIONS(actual.begin(), actual.end(), expected.begin(), expected.end());
+ BOOST_TEST(actual == expected, boost::test_tools::per_element());
}
BOOST_AUTO_TEST_SUITE_END() // TestCs
diff --git a/tests/daemon/table/dead-nonce-list.t.cpp b/tests/daemon/table/dead-nonce-list.t.cpp
index b4bcec9..44b0bfd 100644
--- a/tests/daemon/table/dead-nonce-list.t.cpp
+++ b/tests/daemon/table/dead-nonce-list.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2021, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -145,9 +145,6 @@
scheduler::ScopedEventId addNonceEvent;
};
-const time::nanoseconds PeriodicalInsertionFixture::LIFETIME;
-const time::nanoseconds PeriodicalInsertionFixture::ADD_INTERVAL;
-
BOOST_FIXTURE_TEST_CASE(Lifetime, PeriodicalInsertionFixture)
{
BOOST_CHECK_EQUAL(dnl.getLifetime(), LIFETIME);
diff --git a/tests/daemon/table/fib.t.cpp b/tests/daemon/table/fib.t.cpp
index 101b3b9..1655fac 100644
--- a/tests/daemon/table/fib.t.cpp
+++ b/tests/daemon/table/fib.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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -92,7 +92,7 @@
// [(face1,30), (face2,40)]
BOOST_CHECK_EQUAL(entry.getNextHops().size(), 2);
{
- NextHopList::const_iterator it = entry.getNextHops().begin();
+ auto it = entry.getNextHops().begin();
BOOST_REQUIRE(it != entry.getNextHops().end());
BOOST_CHECK_EQUAL(&it->getFace(), face1.get());
BOOST_CHECK_EQUAL(it->getCost(), 30);
@@ -112,7 +112,7 @@
// [(face2,10), (face1,30)]
BOOST_CHECK_EQUAL(entry.getNextHops().size(), 2);
{
- NextHopList::const_iterator it = entry.getNextHops().begin();
+ auto it = entry.getNextHops().begin();
BOOST_REQUIRE(it != entry.getNextHops().end());
BOOST_CHECK_EQUAL(&it->getFace(), face2.get());
BOOST_CHECK_EQUAL(it->getCost(), 10);
diff --git a/tests/daemon/table/name-tree.t.cpp b/tests/daemon/table/name-tree.t.cpp
index 2649834..6c410aa 100644
--- a/tests/daemon/table/name-tree.t.cpp
+++ b/tests/daemon/table/name-tree.t.cpp
@@ -56,6 +56,7 @@
}
BOOST_AUTO_TEST_SUITE(Hashtable)
+
using name_tree::Hashtable;
BOOST_AUTO_TEST_CASE(Modifiers)
@@ -256,7 +257,7 @@
npe.insertPitEntry(pit2);
BOOST_CHECK_EQUAL(npe.getPitEntries().size(), 2);
- pit::Entry* pit1ptr = pit1.get();
+ auto* pit1ptr = pit1.get();
weak_ptr<pit::Entry> pit1weak(pit1);
pit1.reset();
BOOST_CHECK_EQUAL(pit1weak.use_count(), 1); // npe is the sole owner of pit1
@@ -338,7 +339,6 @@
Entry* npe0 = nt.findExactMatch(name0);
BOOST_CHECK(npe0 == nullptr);
-
// findLongestPrefixMatch
Entry* temp = nullptr;
@@ -493,12 +493,10 @@
}
protected:
- static const size_t N_BUCKETS = 16;
+ static constexpr size_t N_BUCKETS = 16;
NameTree nt;
};
-const size_t EnumerationFixture::N_BUCKETS;
-
BOOST_FIXTURE_TEST_CASE(IteratorFullEnumerate, EnumerationFixture)
{
nt.lookup("/a/b/c");
@@ -556,7 +554,7 @@
// Accept "root" nameA only
auto&& enumerable = nt.partialEnumerate("/a", [] (const Entry& entry) {
- return std::make_pair(entry.getName() == "/a", true);
+ return std::pair(entry.getName() == "/a", true);
});
EnumerationVerifier(enumerable)
@@ -570,7 +568,7 @@
// Accept anything except "root" nameA
auto&& enumerable = nt.partialEnumerate("/a", [] (const Entry& entry) {
- return std::make_pair(entry.getName() != "/a", true);
+ return std::pair(entry.getName() != "/a", true);
});
EnumerationVerifier(enumerable)
@@ -586,7 +584,7 @@
// No NameA
// No SubTree from NameAB
auto&& enumerable = nt.partialEnumerate("/a", [] (const Entry& entry) {
- return std::make_pair(entry.getName() != "/a", entry.getName() != "/a/b");
+ return std::pair(entry.getName() != "/a", entry.getName() != "/a/b");
});
EnumerationVerifier(enumerable)
@@ -604,7 +602,7 @@
// No NameA
// No SubTree from NameAC
auto&& enumerable = nt.partialEnumerate("/a", [] (const Entry& entry) {
- return std::make_pair(entry.getName() != "/a", entry.getName() != "/a/c");
+ return std::pair(entry.getName() != "/a", entry.getName() != "/a/c");
});
EnumerationVerifier(enumerable)
@@ -621,7 +619,7 @@
// No Subtree from NameA
auto&& enumerable = nt.partialEnumerate("/a", [] (const Entry& entry) {
- return std::make_pair(true, entry.getName() != "/a");
+ return std::pair(true, entry.getName() != "/a");
});
EnumerationVerifier(enumerable)
@@ -647,23 +645,20 @@
nt.lookup("/E");
nt.lookup("/F");
- auto&& enumerable = nt.partialEnumerate("/A",
- [] (const Entry& entry) {
- bool visitEntry = false;
- bool visitChildren = false;
+ auto&& enumerable = nt.partialEnumerate("/A", [] (const Entry& entry) {
+ bool visitEntry = false;
+ bool visitChildren = false;
- Name name = entry.getName();
+ const Name& name = entry.getName();
+ if (name == "/" || name == "/A/B" || name == "/A/B/C" || name == "/A/D") {
+ visitEntry = true;
+ }
+ if (name == "/" || name == "/A" || name == "/F") {
+ visitChildren = true;
+ }
- if (name == "/" || name == "/A/B" || name == "/A/B/C" || name == "/A/D") {
- visitEntry = true;
- }
-
- if (name == "/" || name == "/A" || name == "/F") {
- visitChildren = true;
- }
-
- return std::make_pair(visitEntry, visitChildren);
- });
+ return std::pair(visitEntry, visitChildren);
+ });
EnumerationVerifier(enumerable)
.expect("/A/B")
diff --git a/tests/daemon/table/pit.t.cpp b/tests/daemon/table/pit.t.cpp
index 03438d4..defa768 100644
--- a/tests/daemon/table/pit.t.cpp
+++ b/tests/daemon/table/pit.t.cpp
@@ -336,9 +336,9 @@
for (const auto& pitEntry : pit) {
actual.insert(&pitEntry.getInterest());
}
- std::set<const Interest*> expected = {interestA.get(), interestABC1.get(),
- interestABC2.get(), interestD.get()};
- BOOST_CHECK_EQUAL_COLLECTIONS(actual.begin(), actual.end(), expected.begin(), expected.end());
+ const auto expected = std::set{interestA.get(), interestABC1.get(),
+ interestABC2.get(), interestD.get()};
+ BOOST_TEST(actual == expected, boost::test_tools::per_element());
}
BOOST_AUTO_TEST_SUITE_END() // TestPit
diff --git a/tests/daemon/table/strategy-choice.t.cpp b/tests/daemon/table/strategy-choice.t.cpp
index d99ff44..ff6b754 100644
--- a/tests/daemon/table/strategy-choice.t.cpp
+++ b/tests/daemon/table/strategy-choice.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2021, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -48,9 +48,7 @@
insertAndGet(const Name& prefix, const Name& instanceName)
{
BOOST_REQUIRE(sc.insert(prefix, instanceName));
- bool isFound;
- Name foundName;
- std::tie(isFound, foundName) = sc.get(prefix);
+ auto [isFound, foundName] = sc.get(prefix);
BOOST_REQUIRE(isFound);
return foundName;
}
diff --git a/tests/daemon/table/strategy-info-host.t.cpp b/tests/daemon/table/strategy-info-host.t.cpp
index 2a3a33e..e4323e4 100644
--- a/tests/daemon/table/strategy-info-host.t.cpp
+++ b/tests/daemon/table/strategy-info-host.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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -50,8 +50,7 @@
++g_DummyStrategyInfo_count;
}
- virtual
- ~DummyStrategyInfo()
+ ~DummyStrategyInfo() override
{
--g_DummyStrategyInfo_count;
}
@@ -85,19 +84,16 @@
{
StrategyInfoHost host;
g_DummyStrategyInfo_count = 0;
- bool isNew = false;
- DummyStrategyInfo* info = nullptr;
- std::tie(info, isNew) = host.insertStrategyInfo<DummyStrategyInfo>(3503);
+ auto [info, isNew] = host.insertStrategyInfo<DummyStrategyInfo>(3503);
BOOST_CHECK_EQUAL(isNew, true);
BOOST_CHECK_EQUAL(g_DummyStrategyInfo_count, 1);
BOOST_REQUIRE(info != nullptr);
BOOST_CHECK_EQUAL(info->m_id, 3503);
BOOST_CHECK_EQUAL(host.getStrategyInfo<DummyStrategyInfo>(), info);
- DummyStrategyInfo* info2 = nullptr;
- std::tie(info2, isNew) = host.insertStrategyInfo<DummyStrategyInfo>(1032);
- BOOST_CHECK_EQUAL(isNew, false);
+ auto [info2, isNew2] = host.insertStrategyInfo<DummyStrategyInfo>(1032);
+ BOOST_CHECK_EQUAL(isNew2, false);
BOOST_CHECK_EQUAL(g_DummyStrategyInfo_count, 1);
BOOST_CHECK_EQUAL(info2, info);
BOOST_CHECK_EQUAL(info->m_id, 3503);