Adopt more C++17 features throughout the codebase
Change-Id: I31af421d8a977ba2aae23afcda289ff53230897f
diff --git a/tests/benchmarks/timed-execute.hpp b/tests/benchmarks/timed-execute.hpp
index 50bec30..b33873d 100644
--- a/tests/benchmarks/timed-execute.hpp
+++ b/tests/benchmarks/timed-execute.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-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -29,10 +29,10 @@
template<typename F>
time::nanoseconds
-timedExecute(const F& f)
+timedExecute(F&& f)
{
auto before = time::steady_clock::now();
- f();
+ std::invoke(std::forward<F>(f));
auto after = time::steady_clock::now();
return after - before;
}
diff --git a/tests/unit/encoding/tlv.t.cpp b/tests/unit/encoding/tlv.t.cpp
index b21476b..5eaa17a 100644
--- a/tests/unit/encoding/tlv.t.cpp
+++ b/tests/unit/encoding/tlv.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2022 Regents of the University of California.
+ * Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -59,10 +59,10 @@
using StreamIterator = std::istream_iterator<uint8_t>;
#define ASSERT_READ_NUMBER_IS_FAST(T) \
- static_assert(std::is_base_of<detail::ReadNumberFast<T>, detail::ReadNumber<T>>::value, \
+ static_assert(std::is_base_of_v<detail::ReadNumberFast<T>, detail::ReadNumber<T>>, \
# T " should use ReadNumberFast")
#define ASSERT_READ_NUMBER_IS_SLOW(T) \
- static_assert(std::is_base_of<detail::ReadNumberSlow<T>, detail::ReadNumber<T>>::value, \
+ static_assert(std::is_base_of_v<detail::ReadNumberSlow<T>, detail::ReadNumber<T>>, \
# T " should use ReadNumberSlow")
ASSERT_READ_NUMBER_IS_FAST(const uint8_t*);
diff --git a/tests/unit/face.t.cpp b/tests/unit/face.t.cpp
index 7e5b7be..2372e24 100644
--- a/tests/unit/face.t.cpp
+++ b/tests/unit/face.t.cpp
@@ -25,7 +25,6 @@
#include "ndn-cxx/transport/unix-transport.hpp"
#include "ndn-cxx/util/config-file.hpp"
#include "ndn-cxx/util/dummy-client-face.hpp"
-#include "ndn-cxx/util/scheduler.hpp"
#include "tests/test-common.hpp"
#include "tests/unit/io-key-chain-fixture.hpp"
@@ -46,10 +45,10 @@
{
protected:
FaceFixture()
- : face(m_io, m_keyChain, {true, !std::is_same<PrefixRegReply, NoPrefixRegReply>::value})
+ : face(m_io, m_keyChain, {true, !std::is_same_v<PrefixRegReply, NoPrefixRegReply>})
{
- static_assert(std::is_same<PrefixRegReply, WantPrefixRegReply>::value ||
- std::is_same<PrefixRegReply, NoPrefixRegReply>::value, "");
+ static_assert(std::is_same_v<PrefixRegReply, WantPrefixRegReply> ||
+ std::is_same_v<PrefixRegReply, NoPrefixRegReply>, "");
}
/** \brief Execute a prefix registration, and optionally check the name in callback.
diff --git a/tests/unit/lp/packet.t.cpp b/tests/unit/lp/packet.t.cpp
index 588dedf..68f55fc 100644
--- a/tests/unit/lp/packet.t.cpp
+++ b/tests/unit/lp/packet.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2022 Regents of the University of California.
+ * Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -213,8 +213,7 @@
BOOST_CHECK_EQUAL(packet.get<AckField>(2), 2);
BOOST_CHECK_EQUAL(packet.count<FragmentField>(), 1);
- Buffer::const_iterator first, last;
- std::tie(first, last) = packet.get<FragmentField>(0);
+ auto [first, last] = packet.get<FragmentField>(0);
BOOST_CHECK_EQUAL(2, last - first);
BOOST_CHECK_EQUAL(0x03, *first);
BOOST_CHECK_EQUAL(0xe8, *(last - 1));
@@ -253,8 +252,7 @@
packet.wireDecode(wire);
BOOST_CHECK_EQUAL(1, packet.count<FragmentField>());
BOOST_CHECK_EQUAL(0, packet.count<FragIndexField>());
- Buffer::const_iterator first, last;
- std::tie(first, last) = packet.get<FragmentField>(0);
+ auto [first, last] = packet.get<FragmentField>(0);
BOOST_CHECK_EQUAL(2, last - first);
BOOST_CHECK_EQUAL(0x03, *first);
BOOST_CHECK_EQUAL(0xe8, *(last - 1));
diff --git a/tests/unit/mgmt/nfd/controller-fixture.hpp b/tests/unit/mgmt/nfd/controller-fixture.hpp
index ae4ab3c..8afee13 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-2022 Regents of the University of California.
+ * Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -23,7 +23,6 @@
#define NDN_CXX_TESTS_UNIT_MGMT_NFD_CONTROLLER_FIXTURE_HPP
#include "ndn-cxx/mgmt/nfd/controller.hpp"
-#include "ndn-cxx/security/certificate-fetcher-offline.hpp"
#include "ndn-cxx/util/dummy-client-face.hpp"
#include "tests/unit/dummy-validator.hpp"
@@ -63,8 +62,8 @@
ndn::util::DummyClientFace face;
DummyValidator m_validator;
Controller controller;
- Controller::CommandFailCallback commandFailCallback;
- Controller::DatasetFailCallback datasetFailCallback;
+ Controller::CommandFailureCallback commandFailCallback;
+ Controller::DatasetFailureCallback datasetFailCallback;
std::vector<uint32_t> failCodes;
};
diff --git a/tests/unit/mgmt/nfd/controller.t.cpp b/tests/unit/mgmt/nfd/controller.t.cpp
index d871c8b..f7f4a9a 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-2022 Regents of the University of California.
+ * Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -47,7 +47,7 @@
}
protected:
- Controller::CommandSucceedCallback succeedCallback = [this] (const auto& params) {
+ Controller::CommandSuccessCallback succeedCallback = [this] (const auto& params) {
succeeds.push_back(params);
};
std::vector<ControlParameters> succeeds;
diff --git a/tests/unit/security/validity-period.t.cpp b/tests/unit/security/validity-period.t.cpp
index 4a28df2..ff0089f 100644
--- a/tests/unit/security/validity-period.t.cpp
+++ b/tests/unit/security/validity-period.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2022 Regents of the University of California.
+ * Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -85,7 +85,7 @@
BOOST_CHECK_EQUAL(validity2.isValid(), false);
validity2.setPeriod(notBefore, notAfter);
- BOOST_CHECK(validity2.getPeriod() != std::make_pair(time::getUnixEpoch(), time::getUnixEpoch()));
+ BOOST_CHECK(validity2.getPeriod() != std::pair(time::getUnixEpoch(), time::getUnixEpoch()));
BOOST_CHECK_EQUAL(validity2, validity1);
validity1.setPeriod(time::getUnixEpoch(), time::getUnixEpoch() + 10 * 365_days);
diff --git a/tests/unit/signature-info.t.cpp b/tests/unit/signature-info.t.cpp
index 1257851..6924a07 100644
--- a/tests/unit/signature-info.t.cpp
+++ b/tests/unit/signature-info.t.cpp
@@ -447,7 +447,7 @@
info2.setValidityPeriod(security::ValidityPeriod(notBefore, notBefore + 42_days));
BOOST_CHECK_NE(info2.getValidityPeriod(), vp1);
- BOOST_CHECK(info2.getValidityPeriod().getPeriod() == std::make_pair(notBefore, notBefore + 42_days));
+ BOOST_CHECK(info2.getValidityPeriod().getPeriod() == std::pair(notBefore, notBefore + 42_days));
BOOST_CHECK_EQUAL(info2.hasWire(), false);
info2.wireEncode();
diff --git a/tests/unit/util/ostream-joiner.t.cpp b/tests/unit/util/ostream-joiner.t.cpp
index 4c617fa..7e8e63f 100644
--- a/tests/unit/util/ostream-joiner.t.cpp
+++ b/tests/unit/util/ostream-joiner.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2022 Regents of the University of California.
+ * Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -38,7 +38,7 @@
auto joiner1 = ostream_joiner<char>(os, ' ');
auto joiner2 = make_ostream_joiner(os, ' ');
- static_assert(std::is_same<decltype(joiner1), decltype(joiner2)>::value, "");
+ static_assert(std::is_same_v<decltype(joiner1), decltype(joiner2)>, "");
std::vector<int> v(5);
std::iota(v.begin(), v.end(), 1);