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/daemon/table/cs-policy-lru.cpp b/daemon/table/cs-policy-lru.cpp
index 56b21ec..1b477aa 100644
--- a/daemon/table/cs-policy-lru.cpp
+++ b/daemon/table/cs-policy-lru.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,
@@ -71,17 +71,15 @@
BOOST_ASSERT(!m_queue.empty());
EntryRef i = m_queue.front();
m_queue.pop_front();
- this->emitSignal(beforeEvict, i);
+ emitSignal(beforeEvict, i);
}
}
void
LruPolicy::insertToQueue(EntryRef i, bool isNewEntry)
{
- Queue::iterator it;
- bool isNew = false;
// push_back only if i does not exist
- std::tie(it, isNew) = m_queue.push_back(i);
+ auto [it, isNew] = m_queue.push_back(i);
BOOST_ASSERT(isNew == isNewEntry);
if (!isNewEntry) {
diff --git a/daemon/table/cs-policy.cpp b/daemon/table/cs-policy.cpp
index b51aac1..6b24eb3 100644
--- a/daemon/table/cs-policy.cpp
+++ b/daemon/table/cs-policy.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,
@@ -59,7 +59,7 @@
return policyNames;
}
-Policy::Policy(const std::string& policyName)
+Policy::Policy(std::string_view policyName)
: m_policyName(policyName)
{
}
diff --git a/daemon/table/cs-policy.hpp b/daemon/table/cs-policy.hpp
index fb59990..9a4c6ed 100644
--- a/daemon/table/cs-policy.hpp
+++ b/daemon/table/cs-policy.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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -33,7 +33,8 @@
class Cs;
-/** \brief represents a CS replacement policy
+/**
+ * \brief Represents a CS replacement policy
*/
class Policy : noncopyable
{
@@ -42,9 +43,9 @@
static void
registerPolicy(const std::string& policyName = P::POLICY_NAME)
{
- Registry& registry = getRegistry();
- BOOST_ASSERT(registry.count(policyName) == 0);
- registry[policyName] = [] { return make_unique<P>(); };
+ BOOST_ASSERT(!policyName.empty());
+ auto r = getRegistry().insert_or_assign(policyName, [] { return make_unique<P>(); });
+ BOOST_VERIFY(r.second);
}
/** \return a cs::Policy identified by \p policyName,
@@ -59,9 +60,6 @@
getPolicyNames();
public:
- explicit
- Policy(const std::string& policyName);
-
virtual
~Policy() = default;
@@ -190,6 +188,9 @@
evictEntries() = 0;
protected:
+ explicit
+ Policy(std::string_view policyName);
+
DECLARE_SIGNAL_EMIT(beforeEvict)
private: // registry
@@ -200,7 +201,7 @@
getRegistry();
private:
- std::string m_policyName;
+ const std::string m_policyName;
size_t m_limit;
Cs* m_cs;
};
diff --git a/daemon/table/cs.cpp b/daemon/table/cs.cpp
index b240e3d..5fc8301 100644
--- a/daemon/table/cs.cpp
+++ b/daemon/table/cs.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,
@@ -56,7 +56,7 @@
NFD_LOG_DEBUG("insert " << data.getName());
// recognize CachePolicy
- shared_ptr<lp::CachePolicyTag> tag = data.getTag<lp::CachePolicyTag>();
+ auto tag = data.getTag<lp::CachePolicyTag>();
if (tag != nullptr) {
lp::CachePolicyType policy = tag->get().getPolicy();
if (policy == lp::CachePolicyType::NO_CACHE) {
@@ -64,10 +64,8 @@
}
}
- const_iterator it;
- bool isNewEntry = false;
- std::tie(it, isNewEntry) = m_table.emplace(data.shared_from_this(), isUnsolicited);
- Entry& entry = const_cast<Entry&>(*it);
+ auto [it, isNewEntry] = m_table.emplace(data.shared_from_this(), isUnsolicited);
+ auto& entry = const_cast<Entry&>(*it);
entry.updateFreshUntil();
@@ -76,7 +74,6 @@
if (entry.isUnsolicited() && !isUnsolicited) {
entry.clearUnsolicited();
}
-
m_policy->afterRefresh(it);
}
else {
@@ -89,7 +86,7 @@
{
auto first = m_table.lower_bound(prefix);
auto last = m_table.end();
- if (prefix.size() > 0) {
+ if (!prefix.empty()) {
last = m_table.lower_bound(prefix.getSuccessor());
}
return {first, last};
diff --git a/daemon/table/dead-nonce-list.cpp b/daemon/table/dead-nonce-list.cpp
index 55bf346..6149fd6 100644
--- a/daemon/table/dead-nonce-list.cpp
+++ b/daemon/table/dead-nonce-list.cpp
@@ -32,17 +32,6 @@
NFD_LOG_INIT(DeadNonceList);
-const time::nanoseconds DeadNonceList::DEFAULT_LIFETIME;
-const time::nanoseconds DeadNonceList::MIN_LIFETIME;
-const size_t DeadNonceList::INITIAL_CAPACITY;
-const size_t DeadNonceList::MIN_CAPACITY;
-const size_t DeadNonceList::MAX_CAPACITY;
-const DeadNonceList::Entry DeadNonceList::MARK;
-const size_t DeadNonceList::EXPECTED_MARK_COUNT;
-const double DeadNonceList::CAPACITY_UP;
-const double DeadNonceList::CAPACITY_DOWN;
-const size_t DeadNonceList::EVICT_LIMIT;
-
DeadNonceList::DeadNonceList(time::nanoseconds lifetime)
: m_lifetime(lifetime)
, m_capacity(INITIAL_CAPACITY)
@@ -61,15 +50,15 @@
m_adjustCapacityEvent = getScheduler().schedule(m_adjustCapacityInterval, [this] { adjustCapacity(); });
BOOST_ASSERT_MSG(DEFAULT_LIFETIME >= MIN_LIFETIME, "DEFAULT_LIFETIME is too small");
- static_assert(INITIAL_CAPACITY >= MIN_CAPACITY, "INITIAL_CAPACITY is too small");
- static_assert(INITIAL_CAPACITY <= MAX_CAPACITY, "INITIAL_CAPACITY is too large");
+ static_assert(INITIAL_CAPACITY >= MIN_CAPACITY);
+ static_assert(INITIAL_CAPACITY <= MAX_CAPACITY);
BOOST_ASSERT_MSG(static_cast<size_t>(MIN_CAPACITY * CAPACITY_UP) > MIN_CAPACITY,
"CAPACITY_UP must be able to increase from MIN_CAPACITY");
BOOST_ASSERT_MSG(static_cast<size_t>(MAX_CAPACITY * CAPACITY_DOWN) < MAX_CAPACITY,
"CAPACITY_DOWN must be able to decrease from MAX_CAPACITY");
BOOST_ASSERT_MSG(CAPACITY_UP > 1.0, "CAPACITY_UP must adjust up");
BOOST_ASSERT_MSG(CAPACITY_DOWN < 1.0, "CAPACITY_DOWN must adjust down");
- static_assert(EVICT_LIMIT >= 1, "EVICT_LIMIT must be at least 1");
+ static_assert(EVICT_LIMIT >= 1);
}
size_t
diff --git a/daemon/table/fib-entry.cpp b/daemon/table/fib-entry.cpp
index ade4c9f..71c2516 100644
--- a/daemon/table/fib-entry.cpp
+++ b/daemon/table/fib-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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -62,7 +62,7 @@
it->setCost(cost);
this->sortNextHops();
- return std::make_pair(it, isNew);
+ return {it, isNew};
}
bool
diff --git a/daemon/table/fib-entry.hpp b/daemon/table/fib-entry.hpp
index 7460eda..facf248 100644
--- a/daemon/table/fib-entry.hpp
+++ b/daemon/table/fib-entry.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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -48,7 +48,9 @@
*/
using NextHopList = std::vector<NextHop>;
-/** \brief represents a FIB entry
+/**
+ * \brief Represents an entry in the FIB.
+ * \sa Fib
*/
class Entry : noncopyable
{
@@ -115,8 +117,8 @@
name_tree::Entry* m_nameTreeEntry = nullptr;
- friend class name_tree::Entry;
- friend class Fib;
+ friend name_tree::Entry;
+ friend Fib;
};
} // namespace fib
diff --git a/daemon/table/fib.cpp b/daemon/table/fib.cpp
index 99892e6..c6c8f2c 100644
--- a/daemon/table/fib.cpp
+++ b/daemon/table/fib.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,
@@ -135,10 +135,7 @@
void
Fib::addOrUpdateNextHop(Entry& entry, Face& face, uint64_t cost)
{
- NextHopList::iterator it;
- bool isNew;
- std::tie(it, isNew) = entry.addOrUpdateNextHop(face, cost);
-
+ auto [it, isNew] = entry.addOrUpdateNextHop(face, cost);
if (isNew)
this->afterNewNextHop(entry.getPrefix(), *it);
}
diff --git a/daemon/table/fib.hpp b/daemon/table/fib.hpp
index a4b688f..6073533 100644
--- a/daemon/table/fib.hpp
+++ b/daemon/table/fib.hpp
@@ -36,6 +36,7 @@
namespace measurements {
class Entry;
} // namespace measurements
+
namespace pit {
class Entry;
} // namespace pit
diff --git a/daemon/table/measurements-entry.hpp b/daemon/table/measurements-entry.hpp
index fa80327..a70f6e0 100644
--- a/daemon/table/measurements-entry.hpp
+++ b/daemon/table/measurements-entry.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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -36,7 +36,11 @@
namespace measurements {
-/** \brief Represents a Measurements entry
+class Measurements;
+
+/**
+ * \brief Represents an entry in the %Measurements table.
+ * \sa Measurements
*/
class Entry : public StrategyInfoHost, noncopyable
{
@@ -60,8 +64,8 @@
name_tree::Entry* m_nameTreeEntry = nullptr;
- friend class Measurements;
- friend class name_tree::Entry;
+ friend Measurements;
+ friend name_tree::Entry;
};
} // namespace measurements
diff --git a/daemon/table/pit-entry.hpp b/daemon/table/pit-entry.hpp
index 9e4a357..e088e70 100644
--- a/daemon/table/pit-entry.hpp
+++ b/daemon/table/pit-entry.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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -39,21 +39,26 @@
namespace pit {
-/** \brief An unordered collection of in-records
+/**
+ * \brief An unordered collection of in-records
*/
-typedef std::list<InRecord> InRecordCollection;
+using InRecordCollection = std::list<InRecord>;
-/** \brief An unordered collection of out-records
+/**
+ * \brief An unordered collection of out-records
*/
-typedef std::list<OutRecord> OutRecordCollection;
+using OutRecordCollection = std::list<OutRecord>;
-/** \brief An Interest table entry
+/**
+ * \brief Represents an entry in the %Interest table (PIT).
*
- * An Interest table entry represents either a pending Interest or a recently satisfied Interest.
- * Each entry contains a collection of in-records, a collection of out-records,
- * and two timers used in forwarding pipelines.
- * In addition, the entry, in-records, and out-records are subclasses of StrategyInfoHost,
- * which allows forwarding strategy to store arbitrary information on them.
+ * An Interest table entry represents either a pending Interest or a recently satisfied Interest.
+ * Each entry contains a collection of in-records, a collection of out-records,
+ * and two timers used in forwarding pipelines.
+ * In addition, the entry, in-records, and out-records are subclasses of StrategyInfoHost,
+ * which allows forwarding strategy to store arbitrary information on them.
+ *
+ * \sa Pit
*/
class Entry : public StrategyInfoHost, noncopyable
{
@@ -238,7 +243,7 @@
name_tree::Entry* m_nameTreeEntry = nullptr;
- friend class name_tree::Entry;
+ friend name_tree::Entry;
};
} // namespace pit
diff --git a/daemon/table/pit-face-record.cpp b/daemon/table/pit-face-record.cpp
index 639f424..4674b8e 100644
--- a/daemon/table/pit-face-record.cpp
+++ b/daemon/table/pit-face-record.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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -29,7 +29,7 @@
namespace pit {
// Impose a maximum lifetime to prevent integer overflow when calculating m_expiry.
-static const time::milliseconds MAX_LIFETIME{10_days};
+const time::milliseconds MAX_LIFETIME = 10_days;
void
FaceRecord::update(const Interest& interest)
diff --git a/daemon/table/pit-iterator.hpp b/daemon/table/pit-iterator.hpp
index 35e02c5..b788e3c 100644
--- a/daemon/table/pit-iterator.hpp
+++ b/daemon/table/pit-iterator.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, 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,7 +48,7 @@
* \param iPitEntry make this iterator to dereference to the i-th PIT entry in name tree entry
*/
explicit
- Iterator(const NameTree::const_iterator& ntIt = NameTree::const_iterator(), size_t iPitEntry = 0);
+ Iterator(const NameTree::const_iterator& ntIt = {}, size_t iPitEntry = 0);
const Entry&
operator*() const
diff --git a/daemon/table/pit.hpp b/daemon/table/pit.hpp
index c998a4d..b44dce8 100644
--- a/daemon/table/pit.hpp
+++ b/daemon/table/pit.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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -99,7 +99,7 @@
deleteInOutRecords(Entry* entry, const Face& face);
public: // enumeration
- typedef Iterator const_iterator;
+ using const_iterator = Iterator;
/** \return an iterator to the beginning
* \note Iteration order is implementation-defined.
diff --git a/daemon/table/strategy-choice-entry.hpp b/daemon/table/strategy-choice-entry.hpp
index f64d332..ac59234 100644
--- a/daemon/table/strategy-choice-entry.hpp
+++ b/daemon/table/strategy-choice-entry.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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -40,7 +40,9 @@
namespace strategy_choice {
-/** \brief Represents a Strategy Choice entry
+/**
+ * \brief Represents an entry in the %Strategy %Choice table.
+ * \sa StrategyChoice
*/
class Entry : noncopyable
{
@@ -80,7 +82,7 @@
unique_ptr<fw::Strategy> m_strategy;
name_tree::Entry* m_nameTreeEntry = nullptr;
- friend class name_tree::Entry;
+ friend name_tree::Entry;
};
} // namespace strategy_choice