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/face/lp-fragmenter.cpp b/daemon/face/lp-fragmenter.cpp
index 7494ca7..6b1755a 100644
--- a/daemon/face/lp-fragmenter.cpp
+++ b/daemon/face/lp-fragmenter.cpp
@@ -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,
@@ -39,18 +39,18 @@
static_assert(lp::tlv::FragCount < 253, "FragCount TLV-TYPE must fit in 1 octet");
static_assert(lp::tlv::Fragment < 253, "Fragment TLV-TYPE must fit in 1 octet");
-/** \brief maximum overhead on a single fragment,
- * not counting other NDNLPv2 headers
+/**
+ * \brief Maximum overhead on a single fragment, not counting other NDNLPv2 headers.
*/
-static const size_t MAX_SINGLE_FRAG_OVERHEAD =
+const size_t MAX_SINGLE_FRAG_OVERHEAD =
1 + 9 + // LpPacket TLV-TYPE and TLV-LENGTH
1 + 1 + 8 + // Sequence TLV
1 + 9; // Fragment TLV-TYPE and TLV-LENGTH
-/** \brief maximum overhead of adding fragmentation to payload,
- * not counting other NDNLPv2 headers
+/**
+ * \brief Maximum overhead of adding fragmentation to payload, not counting other NDNLPv2 headers.
*/
-static const size_t MAX_FRAG_OVERHEAD =
+const size_t MAX_FRAG_OVERHEAD =
1 + 9 + // LpPacket TLV-TYPE and TLV-LENGTH
1 + 1 + 8 + // Sequence TLV
1 + 1 + 8 + // FragIndex TLV
@@ -86,18 +86,17 @@
// fast path: fragmentation not needed
// To qualify for fast path, the packet must have space for adding a sequence number,
// because another NDNLPv2 feature may require the sequence number.
- return std::make_tuple(true, std::vector<lp::Packet>{packet});
+ return {true, {packet}};
}
- ndn::Buffer::const_iterator netPktBegin, netPktEnd;
- std::tie(netPktBegin, netPktEnd) = packet.get<lp::FragmentField>();
+ auto [netPktBegin, netPktEnd] = packet.get<lp::FragmentField>();
size_t netPktSize = std::distance(netPktBegin, netPktEnd);
// compute size of other NDNLPv2 headers to be placed on the first fragment
size_t firstHeaderSize = 0;
- const Block& packetWire = packet.wireEncode();
+ const auto& packetWire = packet.wireEncode();
if (packetWire.type() == lp::tlv::LpPacket) {
- for (const Block& element : packetWire.elements()) {
+ for (const auto& element : packetWire.elements()) {
if (element.type() != lp::tlv::Fragment) {
firstHeaderSize += element.size();
}
@@ -107,7 +106,7 @@
// compute payload size
if (MAX_FRAG_OVERHEAD + firstHeaderSize + 1 > mtu) { // 1-octet fragment
NFD_LOG_FACE_WARN("fragmentation error, MTU too small for first fragment: DROP");
- return std::make_tuple(false, std::vector<lp::Packet>{});
+ return {false, {}};
}
size_t firstPayloadSize = std::min(netPktSize, mtu - firstHeaderSize - MAX_FRAG_OVERHEAD);
size_t payloadSize = mtu - MAX_FRAG_OVERHEAD;
@@ -117,7 +116,7 @@
// compute FragCount
if (fragCount > m_options.nMaxFragments) {
NFD_LOG_FACE_WARN("fragmentation error, FragCount over limit: DROP");
- return std::make_tuple(false, std::vector<lp::Packet>{});
+ return {false, {}};
}
// populate fragments
@@ -139,7 +138,7 @@
}
BOOST_ASSERT(fragIndex == fragCount);
- return std::make_tuple(true, frags);
+ return {true, frags};
}
std::ostream&