build: switch to C++17
Change-Id: I92039300ce845de0312dceccb94c128229ed60c4
diff --git a/.jenkins.d/40-headers-check.sh b/.jenkins.d/40-headers-check.sh
index 8ee3339..40e5f34 100755
--- a/.jenkins.d/40-headers-check.sh
+++ b/.jenkins.d/40-headers-check.sh
@@ -16,7 +16,7 @@
fi
CXX=${CXX:-g++}
-STD=-std=c++14
+STD=-std=c++17
CXXFLAGS="-O2 -Wall -Wno-unneeded-internal-declaration -Wno-unused-const-variable $(pkg-config --cflags libndn-cxx $PCFILE)"
INCLUDEDIR="$(pkg-config --variable=includedir $PCFILE)"/$PROJ
diff --git a/.waf-tools/default-compiler-flags.py b/.waf-tools/default-compiler-flags.py
index 5f2d0b3..8c71871 100644
--- a/.waf-tools/default-compiler-flags.py
+++ b/.waf-tools/default-compiler-flags.py
@@ -139,7 +139,7 @@
"""
def getGeneralFlags(self, conf):
flags = super(GccBasicFlags, self).getGeneralFlags(conf)
- flags['CXXFLAGS'] += ['-std=c++14']
+ flags['CXXFLAGS'] += ['-std=c++17']
if Utils.unversioned_sys_platform() != 'darwin':
flags['LINKFLAGS'] += ['-fuse-ld=lld']
return flags
diff --git a/README.md b/README.md
index d4638b7..e01e4b3 100644
--- a/README.md
+++ b/README.md
@@ -8,10 +8,10 @@
[![CI](https://github.com/named-data/ndn-cxx/actions/workflows/ci.yml/badge.svg)](https://github.com/named-data/ndn-cxx/actions/workflows/ci.yml)
[![Docs](https://github.com/named-data/ndn-cxx/actions/workflows/docs.yml/badge.svg)](https://github.com/named-data/ndn-cxx/actions/workflows/docs.yml)
-![Language](https://img.shields.io/badge/C%2B%2B-14-blue)
+![Language](https://img.shields.io/badge/C%2B%2B-17-blue)
![Latest version](https://img.shields.io/github/v/tag/named-data/ndn-cxx?label=Latest%20version)
-**ndn-cxx** is a C++14 library implementing Named Data Networking (NDN) primitives
+**ndn-cxx** is a C++17 library implementing Named Data Networking (NDN) primitives
that can be used to write various NDN applications. The library is currently being
used by the following projects:
diff --git a/docs/code-style.rst b/docs/code-style.rst
index 63bd327..2baac21 100644
--- a/docs/code-style.rst
+++ b/docs/code-style.rst
@@ -180,7 +180,7 @@
switch (condition) {
case ABC: // 2 space indent
statements; // 4 space indent
- NDN_CXX_FALLTHROUGH;
+ [[fallthrough]];
case DEF:
statements;
@@ -211,7 +211,7 @@
// Correct style
case A1: {
statements;
- NDN_CXX_FALLTHROUGH;
+ [[fallthrough]];
}
// Incorrect style: braces should cover the entire case block
@@ -232,7 +232,7 @@
switch (condition) {
case ABC: // no indent
statements; // 2 space indent
- NDN_CXX_FALLTHROUGH;
+ [[fallthrough]];
case DEF:
statements;
@@ -243,11 +243,11 @@
break;
}
- The ``NDN_CXX_FALLTHROUGH`` annotation must be included whenever there is
- a case without a break statement. Leaving the break out is a common error,
+ The ``[[fallthrough]]`` annotation must be included whenever there is a
+ case without a break statement. Leaving the break out is a common error,
and it must be made clear that it is intentional when it is not there.
- Moreover, modern compilers will warn when a case that falls through is not
- explicitly annotated.
+ Moreover, modern compilers will warn when a case that falls through is
+ not explicitly annotated.
1.11. A ``try-catch`` statement should have the following form:
diff --git a/docs/index.rst b/docs/index.rst
index df9f084..00943d5 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -19,7 +19,7 @@
release-notes
releases
-**ndn-cxx** is a C++14 library implementing Named Data Networking (NDN) primitives
+**ndn-cxx** is a C++17 library implementing Named Data Networking (NDN) primitives
that can be used to write various NDN applications. The library is currently being
used by the following projects:
diff --git a/ndn-cxx/detail/common.hpp b/ndn-cxx/detail/common.hpp
index 13570c9..c64e4d8 100644
--- a/ndn-cxx/detail/common.hpp
+++ b/ndn-cxx/detail/common.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 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).
*
@@ -30,9 +30,9 @@
#include "ndn-cxx/detail/config.hpp"
-// require C++14
-#if __cplusplus < 201402L
-#error "ndn-cxx applications must be compiled using the C++14 standard (-std=c++14)"
+// require C++17
+#if __cplusplus < 201703L
+#error "ndn-cxx applications must be compiled using the C++17 standard (-std=c++17)"
#endif
// ndn-cxx specific macros declared in this and other headers must have NDN_CXX_ prefix
diff --git a/ndn-cxx/encoding/block.hpp b/ndn-cxx/encoding/block.hpp
index 9f8a772..b943982 100644
--- a/ndn-cxx/encoding/block.hpp
+++ b/ndn-cxx/encoding/block.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).
*
@@ -162,7 +162,7 @@
* @return `true` and the parsed Block if parsing succeeds; otherwise `false` and an invalid Block
* @note This function does not throw upon decoding failure.
*/
- NDN_CXX_NODISCARD static std::tuple<bool, Block>
+ [[nodiscard]] static std::tuple<bool, Block>
fromBuffer(ConstBufferPtr buffer, size_t offset = 0);
/** @brief Try to parse Block from a byte range
@@ -172,7 +172,7 @@
* @note This overload copies the TLV element octets to an internal buffer.
* @note This function does not throw upon decoding failure.
*/
- NDN_CXX_NODISCARD static std::tuple<bool, Block>
+ [[nodiscard]] static std::tuple<bool, Block>
fromBuffer(span<const uint8_t> buffer);
/** @brief Parse Block from an input stream
diff --git a/ndn-cxx/encoding/tlv.hpp b/ndn-cxx/encoding/tlv.hpp
index 176d609..35a46e4 100644
--- a/ndn-cxx/encoding/tlv.hpp
+++ b/ndn-cxx/encoding/tlv.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).
*
@@ -176,7 +176,7 @@
* @return true if number was successfully read from input, false otherwise
*/
template<typename Iterator>
-NDN_CXX_NODISCARD bool
+[[nodiscard]] bool
readVarNumber(Iterator& begin, Iterator end, uint64_t& number) noexcept;
/**
@@ -193,7 +193,7 @@
* the TLV-TYPE is zero or larger than 2^32-1 (maximum allowed by the packet format).
*/
template<typename Iterator>
-NDN_CXX_NODISCARD bool
+[[nodiscard]] bool
readType(Iterator& begin, Iterator end, uint32_t& type) noexcept;
/**
diff --git a/ndn-cxx/impl/face-impl.hpp b/ndn-cxx/impl/face-impl.hpp
index 239885d..86ccb9e 100644
--- a/ndn-cxx/impl/face-impl.hpp
+++ b/ndn-cxx/impl/face-impl.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).
*
@@ -109,7 +109,7 @@
void
asyncRemovePendingInterest(detail::RecordId id)
{
- m_face.getIoService().post([id, w = weak_ptr<Impl>{shared_from_this()}] { // use weak_from_this() in C++17
+ m_face.getIoService().post([id, w = weak_from_this()] {
auto impl = w.lock();
if (impl != nullptr) {
impl->m_pendingInterestTable.erase(id);
@@ -195,7 +195,7 @@
void
asyncUnsetInterestFilter(detail::RecordId id)
{
- m_face.getIoService().post([id, w = weak_ptr<Impl>{shared_from_this()}] { // use weak_from_this() in C++17
+ m_face.getIoService().post([id, w = weak_from_this()] {
auto impl = w.lock();
if (impl != nullptr) {
impl->unsetInterestFilter(id);
@@ -292,7 +292,7 @@
const UnregisterPrefixSuccessCallback& onSuccess,
const UnregisterPrefixFailureCallback& onFailure)
{
- m_face.getIoService().post([=, w = weak_ptr<Impl>{shared_from_this()}] { // use weak_from_this() in C++17
+ m_face.getIoService().post([=, w = weak_from_this()] {
auto impl = w.lock();
if (impl != nullptr) {
impl->unregisterPrefix(id, onSuccess, onFailure);
diff --git a/ndn-cxx/impl/record-container.hpp b/ndn-cxx/impl/record-container.hpp
index e149b40..12fff0d 100644
--- a/ndn-cxx/impl/record-container.hpp
+++ b/ndn-cxx/impl/record-container.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 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).
*
@@ -173,7 +173,7 @@
});
}
- NDN_CXX_NODISCARD bool
+ [[nodiscard]] bool
empty() const noexcept
{
return m_container.empty();
diff --git a/ndn-cxx/interest-filter.hpp b/ndn-cxx/interest-filter.hpp
index 66d6cd2..078ac1c 100644
--- a/ndn-cxx/interest-filter.hpp
+++ b/ndn-cxx/interest-filter.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).
*
@@ -125,7 +125,7 @@
/**
* \brief Get whether Interest loopback is allowed.
*/
- NDN_CXX_NODISCARD bool
+ [[nodiscard]] bool
allowsLoopback() const noexcept
{
return m_allowsLoopback;
diff --git a/ndn-cxx/interest.cpp b/ndn-cxx/interest.cpp
index b6d8f3c..345d60b 100644
--- a/ndn-cxx/interest.cpp
+++ b/ndn-cxx/interest.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).
*
@@ -758,8 +758,7 @@
auto printOne = [&] (const auto&... args) {
os << delim;
delim = '&';
- using expand = int[];
- (void)expand{(os << args, 0)...}; // use a fold expression when we switch to C++17
+ (os << ... << args);
};
if (interest.getCanBePrefix()) {
diff --git a/ndn-cxx/interest.hpp b/ndn-cxx/interest.hpp
index d282052..9777c14 100644
--- a/ndn-cxx/interest.hpp
+++ b/ndn-cxx/interest.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).
*
@@ -464,7 +464,7 @@
Interest&
setSignatureValueInternal(Block sigValue);
- NDN_CXX_NODISCARD shared_ptr<Buffer>
+ [[nodiscard]] shared_ptr<Buffer>
computeParametersDigest() const;
/** @brief Append a ParametersSha256DigestComponent to the Interest's name
diff --git a/ndn-cxx/key-locator.hpp b/ndn-cxx/key-locator.hpp
index d12ac23..ec5688f 100644
--- a/ndn-cxx/key-locator.hpp
+++ b/ndn-cxx/key-locator.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).
*
@@ -71,7 +71,7 @@
wireDecode(const Block& wire);
public: // attributes
- NDN_CXX_NODISCARD bool
+ [[nodiscard]] bool
empty() const
{
return holds_alternative<monostate>(m_locator);
diff --git a/ndn-cxx/lp/packet.hpp b/ndn-cxx/lp/packet.hpp
index 4febf54..5b90549 100644
--- a/ndn-cxx/lp/packet.hpp
+++ b/ndn-cxx/lp/packet.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).
*
@@ -61,7 +61,7 @@
* \retval true packet has no field
* \retval false packet has one or more fields
*/
- NDN_CXX_NODISCARD bool
+ [[nodiscard]] bool
empty() const
{
return m_wire.elements_size() == 0;
@@ -73,7 +73,7 @@
* \details This is equivalent to count() > 0
*/
template<typename FIELD>
- NDN_CXX_NODISCARD bool
+ [[nodiscard]] bool
has() const
{
return count<FIELD>() > 0;
@@ -83,7 +83,7 @@
* \brief Returns the number of occurrences of \c FIELD.
*/
template<typename FIELD>
- NDN_CXX_NODISCARD size_t
+ [[nodiscard]] size_t
count() const
{
return std::count_if(m_wire.elements_begin(), m_wire.elements_end(),
@@ -115,7 +115,7 @@
* \brief Returns the values of all occurrences of \c FIELD.
*/
template<typename FIELD>
- NDN_CXX_NODISCARD std::vector<typename FIELD::ValueType>
+ [[nodiscard]] std::vector<typename FIELD::ValueType>
list() const
{
std::vector<typename FIELD::ValueType> output;
diff --git a/ndn-cxx/metadata-object.hpp b/ndn-cxx/metadata-object.hpp
index 534b1fa..6ad674a 100644
--- a/ndn-cxx/metadata-object.hpp
+++ b/ndn-cxx/metadata-object.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 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).
*
@@ -79,7 +79,7 @@
*
* @throw tlv::Error @p discoveryInterestName is not valid
*/
- NDN_CXX_NODISCARD Data
+ [[nodiscard]] Data
makeData(Name discoveryInterestName,
KeyChain& keyChain,
const ndn::security::SigningInfo& si = security::SigningInfo(),
@@ -123,7 +123,7 @@
*
* @param name prefix of data collection
*/
- NDN_CXX_NODISCARD static Interest
+ [[nodiscard]] static Interest
makeDiscoveryInterest(Name name);
private:
diff --git a/ndn-cxx/name-component.hpp b/ndn-cxx/name-component.hpp
index afd42a0..9f196f2 100644
--- a/ndn-cxx/name-component.hpp
+++ b/ndn-cxx/name-component.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).
*
@@ -543,7 +543,7 @@
}
public: // comparison
- NDN_CXX_NODISCARD bool
+ [[nodiscard]] bool
empty() const noexcept
{
return value_size() == 0;
diff --git a/ndn-cxx/name.hpp b/ndn-cxx/name.hpp
index 62066fc..297c1ef 100644
--- a/ndn-cxx/name.hpp
+++ b/ndn-cxx/name.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).
*
@@ -142,7 +142,7 @@
/**
* @brief Checks if the name is empty, i.e., has no components.
*/
- NDN_CXX_NODISCARD bool
+ [[nodiscard]] bool
empty() const noexcept
{
return m_wire.elements().empty();
diff --git a/ndn-cxx/net/face-uri.hpp b/ndn-cxx/net/face-uri.hpp
index 87555f4..bca98c9 100644
--- a/ndn-cxx/net/face-uri.hpp
+++ b/ndn-cxx/net/face-uri.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,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -67,7 +67,7 @@
FaceUri(const char* uri);
/// Exception-safe parsing.
- NDN_CXX_NODISCARD bool
+ [[nodiscard]] bool
parse(const std::string& uri);
public: // scheme-specific construction
diff --git a/ndn-cxx/net/network-monitor.hpp b/ndn-cxx/net/network-monitor.hpp
index f9dcc8e..3bd8927 100644
--- a/ndn-cxx/net/network-monitor.hpp
+++ b/ndn-cxx/net/network-monitor.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 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).
*
@@ -92,7 +92,7 @@
* @warning May return incomplete results if called before the
* #onEnumerationCompleted signal has been emitted.
*/
- NDN_CXX_NODISCARD std::vector<shared_ptr<const NetworkInterface>>
+ [[nodiscard]] std::vector<shared_ptr<const NetworkInterface>>
listNetworkInterfaces() const;
protected:
diff --git a/ndn-cxx/security/impl/openssl-helper.hpp b/ndn-cxx/security/impl/openssl-helper.hpp
index 310a283..e348391 100644
--- a/ndn-cxx/security/impl/openssl-helper.hpp
+++ b/ndn-cxx/security/impl/openssl-helper.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).
*
@@ -31,10 +31,10 @@
namespace security {
namespace detail {
-NDN_CXX_NODISCARD const EVP_MD*
+[[nodiscard]] const EVP_MD*
digestAlgorithmToEvpMd(DigestAlgorithm algo);
-NDN_CXX_NODISCARD int
+[[nodiscard]] int
getEvpPkeyType(const EVP_PKEY* key);
class EvpMdCtx : noncopyable
@@ -86,10 +86,10 @@
return m_bio;
}
- NDN_CXX_NODISCARD bool
+ [[nodiscard]] bool
read(span<uint8_t> buf) const noexcept;
- NDN_CXX_NODISCARD bool
+ [[nodiscard]] bool
write(span<const uint8_t> buf) noexcept;
private:
diff --git a/ndn-cxx/security/key-chain.cpp b/ndn-cxx/security/key-chain.cpp
index bcedeb5..dd30d73 100644
--- a/ndn-cxx/security/key-chain.cpp
+++ b/ndn-cxx/security/key-chain.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).
*
@@ -114,13 +114,13 @@
class KeyChain::Locator
{
public:
- NDN_CXX_NODISCARD bool
+ [[nodiscard]] bool
empty() const
{
return scheme.empty();
}
- NDN_CXX_NODISCARD std::string
+ [[nodiscard]] std::string
canonical() const
{
return scheme + ':' + location;
diff --git a/ndn-cxx/security/pib/certificate-container.hpp b/ndn-cxx/security/pib/certificate-container.hpp
index 34f6488..52b4520 100644
--- a/ndn-cxx/security/pib/certificate-container.hpp
+++ b/ndn-cxx/security/pib/certificate-container.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).
*
@@ -121,7 +121,7 @@
/**
* @brief Check whether the container is empty.
*/
- NDN_CXX_NODISCARD bool
+ [[nodiscard]] bool
empty() const noexcept
{
return m_certNames.empty();
diff --git a/ndn-cxx/security/pib/identity-container.hpp b/ndn-cxx/security/pib/identity-container.hpp
index b354ade..75fe3f4 100644
--- a/ndn-cxx/security/pib/identity-container.hpp
+++ b/ndn-cxx/security/pib/identity-container.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).
*
@@ -122,7 +122,7 @@
/**
* @brief Check whether the container is empty.
*/
- NDN_CXX_NODISCARD bool
+ [[nodiscard]] bool
empty() const noexcept
{
return m_identityNames.empty();
diff --git a/ndn-cxx/security/pib/key-container.hpp b/ndn-cxx/security/pib/key-container.hpp
index 19ebfa9..cb9b211 100644
--- a/ndn-cxx/security/pib/key-container.hpp
+++ b/ndn-cxx/security/pib/key-container.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).
*
@@ -122,7 +122,7 @@
/**
* @brief Check whether the container is empty.
*/
- NDN_CXX_NODISCARD bool
+ [[nodiscard]] bool
empty() const noexcept
{
return m_keyNames.empty();
diff --git a/ndn-cxx/security/tpm/back-end.hpp b/ndn-cxx/security/tpm/back-end.hpp
index 41078f2..dfe50cd 100644
--- a/ndn-cxx/security/tpm/back-end.hpp
+++ b/ndn-cxx/security/tpm/back-end.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 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).
*
@@ -155,7 +155,7 @@
*
* @return True if the TPM was unlocked.
*/
- NDN_CXX_NODISCARD virtual bool
+ [[nodiscard]] virtual bool
unlockTpm(const char* pw, size_t pwLen) const;
protected: // helper methods
diff --git a/ndn-cxx/security/tpm/tpm.hpp b/ndn-cxx/security/tpm/tpm.hpp
index 4c239ed..1ffdeb1 100644
--- a/ndn-cxx/security/tpm/tpm.hpp
+++ b/ndn-cxx/security/tpm/tpm.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).
*
@@ -117,7 +117,7 @@
* @retval false the signature is not valid
* @retval indeterminate the key does not exist
*/
- NDN_CXX_NODISCARD boost::logic::tribool
+ [[nodiscard]] boost::logic::tribool
verify(const InputBuffers& bufs, span<const uint8_t> sig, const Name& keyName,
DigestAlgorithm digestAlgorithm) const;
@@ -156,7 +156,7 @@
* @param password The password to unlock the TPM.
* @param passwordLength The password size.
*/
- NDN_CXX_NODISCARD bool
+ [[nodiscard]] bool
unlockTpm(const char* password, size_t passwordLength) const;
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // operations accessible only by KeyChain
diff --git a/ndn-cxx/security/verification-helpers.hpp b/ndn-cxx/security/verification-helpers.hpp
index 36cb721..26cc824 100644
--- a/ndn-cxx/security/verification-helpers.hpp
+++ b/ndn-cxx/security/verification-helpers.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).
*
@@ -51,21 +51,21 @@
/**
* @brief Verify @p blobs using @p key against @p sig.
*/
-NDN_CXX_NODISCARD bool
+[[nodiscard]] bool
verifySignature(const InputBuffers& blobs, span<const uint8_t> sig, const transform::PublicKey& key);
/**
* @brief Verify @p blobs using @p key against @p sig.
* @note @p key must be a public key in PKCS #8 format.
*/
-NDN_CXX_NODISCARD bool
+[[nodiscard]] bool
verifySignature(const InputBuffers& blobs, span<const uint8_t> sig, span<const uint8_t> key);
/**
* @brief Verify @p data using @p key.
* @note @p key must be a public key in PKCS #8 format.
*/
-NDN_CXX_NODISCARD bool
+[[nodiscard]] bool
verifySignature(const Data& data, span<const uint8_t> key);
/**
@@ -73,33 +73,33 @@
* @note @p key must be a public key in PKCS #8 format.
* @note This method verifies only signature of the signed interest.
*/
-NDN_CXX_NODISCARD bool
+[[nodiscard]] bool
verifySignature(const Interest& interest, span<const uint8_t> key);
/**
* @brief Verify @p data using @p key.
*/
-NDN_CXX_NODISCARD bool
+[[nodiscard]] bool
verifySignature(const Data& data, const transform::PublicKey& key);
/**
* @brief Verify @p interest using @p key.
* @note This method verifies only signature of the signed interest.
*/
-NDN_CXX_NODISCARD bool
+[[nodiscard]] bool
verifySignature(const Interest& interest, const transform::PublicKey& key);
/**
* @brief Verify @p data using @p key.
*/
-NDN_CXX_NODISCARD bool
+[[nodiscard]] bool
verifySignature(const Data& data, const pib::Key& key);
/**
* @brief Verify @p interest using @p key.
* @note This method verifies only signature of the signed interest.
*/
-NDN_CXX_NODISCARD bool
+[[nodiscard]] bool
verifySignature(const Interest& interest, const pib::Key& key);
/**
@@ -107,7 +107,7 @@
*
* If @p cert is nullopt, @p data assumed to be self-verifiable (with digest or attributes)
*/
-NDN_CXX_NODISCARD bool
+[[nodiscard]] bool
verifySignature(const Data& data, const optional<Certificate>& cert);
/**
@@ -116,13 +116,13 @@
*
* If @p cert is nullptr, @p interest assumed to be self-verifiable (with digest or attributes)
*/
-NDN_CXX_NODISCARD bool
+[[nodiscard]] bool
verifySignature(const Interest& interest, const optional<Certificate>& cert);
/**
* @brief Verify @p data using @p tpm and @p keyName with the @p digestAlgorithm.
*/
-NDN_CXX_NODISCARD bool
+[[nodiscard]] bool
verifySignature(const Data& data, const tpm::Tpm& tpm, const Name& keyName,
DigestAlgorithm digestAlgorithm);
@@ -130,7 +130,7 @@
* @brief Verify @p interest using @p tpm and @p keyName with the @p digestAlgorithm.
* @note This method verifies only signature of the signed interest.
*/
-NDN_CXX_NODISCARD bool
+[[nodiscard]] bool
verifySignature(const Interest& interest, const tpm::Tpm& tpm, const Name& keyName,
DigestAlgorithm digestAlgorithm);
diff --git a/ndn-cxx/util/backports.hpp b/ndn-cxx/util/backports.hpp
index 6015153..5a41294 100644
--- a/ndn-cxx/util/backports.hpp
+++ b/ndn-cxx/util/backports.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).
*
@@ -28,50 +28,12 @@
#include <boost/predef/compiler/gcc.h>
#include <boost/predef/compiler/visualc.h>
-#ifdef __has_cpp_attribute
-# define NDN_CXX_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
-#else
-# define NDN_CXX_HAS_CPP_ATTRIBUTE(x) 0
-#endif
-
-#ifdef __has_include
-# define NDN_CXX_HAS_INCLUDE(x) __has_include(x)
-#else
-# define NDN_CXX_HAS_INCLUDE(x) 0
-#endif
-
-//
-// https://wg21.link/P0188
-// [[fallthrough]] attribute (C++17)
-//
-#if (__cplusplus > 201402L) && NDN_CXX_HAS_CPP_ATTRIBUTE(fallthrough)
-# define NDN_CXX_FALLTHROUGH [[fallthrough]]
-#elif NDN_CXX_HAS_CPP_ATTRIBUTE(clang::fallthrough)
-# define NDN_CXX_FALLTHROUGH [[clang::fallthrough]]
-#elif NDN_CXX_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
-# define NDN_CXX_FALLTHROUGH [[gnu::fallthrough]]
-#elif BOOST_COMP_GNUC >= BOOST_VERSION_NUMBER(7,0,0)
-# define NDN_CXX_FALLTHROUGH __attribute__((fallthrough))
-#else
-# define NDN_CXX_FALLTHROUGH ((void)0)
-#endif
-
-//
-// https://wg21.link/P0189
-// [[nodiscard]] attribute (C++17)
-//
-#if (__cplusplus > 201402L) && NDN_CXX_HAS_CPP_ATTRIBUTE(nodiscard)
-# define NDN_CXX_NODISCARD [[nodiscard]]
-#elif NDN_CXX_HAS_CPP_ATTRIBUTE(gnu::warn_unused_result)
-# define NDN_CXX_NODISCARD [[gnu::warn_unused_result]]
-#else
-# define NDN_CXX_NODISCARD
-#endif
-
#ifndef NDN_CXX_HAVE_STD_TO_STRING
#include <boost/lexical_cast.hpp>
#endif
+#include <utility>
+
namespace ndn {
//
@@ -90,30 +52,6 @@
#endif // NDN_CXX_HAVE_STD_TO_STRING
//
-// https://wg21.link/P0025
-// std::clamp() (C++17)
-//
-#if __cpp_lib_clamp >= 201603L
-using std::clamp;
-#else
-template<typename T, typename Compare>
-constexpr const T&
-clamp(const T& v, const T& lo, const T& hi, Compare comp)
-{
- BOOST_ASSERT(!comp(hi, lo));
- return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
-}
-
-template<typename T>
-constexpr const T&
-clamp(const T& v, const T& lo, const T& hi)
-{
- BOOST_ASSERT(!(hi < lo));
- return (v < lo) ? lo : (hi < v) ? hi : v;
-}
-#endif // __cpp_lib_clamp
-
-//
// https://wg21.link/P1682
// std::to_underlying() (C++23)
//
@@ -121,7 +59,7 @@
using std::to_underlying;
#else
template<typename T>
-NDN_CXX_NODISCARD constexpr std::underlying_type_t<T>
+[[nodiscard]] constexpr std::underlying_type_t<T>
to_underlying(T val) noexcept
{
// instantiating underlying_type with a non-enum type is UB before C++20
diff --git a/ndn-cxx/util/logging.hpp b/ndn-cxx/util/logging.hpp
index bdb0a89..644bf77 100644
--- a/ndn-cxx/util/logging.hpp
+++ b/ndn-cxx/util/logging.hpp
@@ -50,7 +50,7 @@
/**
* \brief Get list of all registered logger names.
*/
- NDN_CXX_NODISCARD static std::set<std::string>
+ [[nodiscard]] static std::set<std::string>
getLoggerNames();
/** \brief Set severity level.
@@ -118,7 +118,7 @@
/**
* \brief Create stream log destination using default formatting.
*/
- NDN_CXX_NODISCARD static boost::shared_ptr<boost::log::sinks::sink>
+ [[nodiscard]] static boost::shared_ptr<boost::log::sinks::sink>
makeDefaultStreamDestination(shared_ptr<std::ostream> os, bool wantAutoFlush = true);
private:
@@ -130,7 +130,7 @@
void
registerLoggerNameImpl(std::string name);
- NDN_CXX_NODISCARD std::set<std::string>
+ [[nodiscard]] std::set<std::string>
getLoggerNamesImpl() const;
/**
diff --git a/ndn-cxx/util/ostream-joiner.hpp b/ndn-cxx/util/ostream-joiner.hpp
index 8570102..e187854 100644
--- a/ndn-cxx/util/ostream-joiner.hpp
+++ b/ndn-cxx/util/ostream-joiner.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 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).
*
@@ -19,17 +19,18 @@
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
*/
-/** \file
- * \brief Backport of ostream_joiner from the Library Fundamentals v2 TS
- * \sa https://en.cppreference.com/w/cpp/experimental/ostream_joiner
+/**
+ * \file
+ * \brief Backport of `ostream_joiner` from the Library Fundamentals v2 TS
+ * \sa https://en.cppreference.com/w/cpp/experimental/ostream_joiner
*/
#ifndef NDN_CXX_UTIL_OSTREAM_JOINER_HPP
#define NDN_CXX_UTIL_OSTREAM_JOINER_HPP
-#include "ndn-cxx/util/backports.hpp"
+#include "ndn-cxx/detail/common.hpp"
-#if NDN_CXX_HAS_INCLUDE(<experimental/iterator>)
+#if __has_include(<experimental/iterator>)
# include <experimental/iterator>
# if __cpp_lib_experimental_ostream_joiner >= 201411
# define NDN_CXX_HAVE_EXPERIMENTAL_OSTREAM_JOINER
diff --git a/ndn-cxx/util/regex/regex-top-matcher.cpp b/ndn-cxx/util/regex/regex-top-matcher.cpp
index f326ca5..0a334ce 100644
--- a/ndn-cxx/util/regex/regex-top-matcher.cpp
+++ b/ndn-cxx/util/regex/regex-top-matcher.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2019 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).
*
@@ -206,7 +206,7 @@
case '^':
case '$':
newStr.push_back('\\');
- NDN_CXX_FALLTHROUGH;
+ [[fallthrough]];
default:
newStr.push_back(c);
break;
diff --git a/ndn-cxx/util/rtt-estimator.cpp b/ndn-cxx/util/rtt-estimator.cpp
index a0a4779..04310d2 100644
--- a/ndn-cxx/util/rtt-estimator.cpp
+++ b/ndn-cxx/util/rtt-estimator.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (C) 2016-2019, Arizona Board of Regents.
+ * Copyright (C) 2016-2023, Arizona Board of Regents.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -59,15 +59,15 @@
beta * time::abs(m_sRtt - rtt));
m_sRtt = time::duration_cast<time::nanoseconds>((1 - alpha) * m_sRtt + alpha * rtt);
}
- m_rto = clamp(m_sRtt + m_options->k * m_rttVar,
- m_options->minRto, m_options->maxRto);
+ m_rto = std::clamp(m_sRtt + m_options->k * m_rttVar,
+ m_options->minRto, m_options->maxRto);
}
void
RttEstimator::backoffRto()
{
- m_rto = clamp(m_rto * m_options->rtoBackoffMultiplier,
- m_options->minRto, m_options->maxRto);
+ m_rto = std::clamp(m_rto * m_options->rtoBackoffMultiplier,
+ m_options->minRto, m_options->maxRto);
}
void
diff --git a/ndn-cxx/util/scheduler.cpp b/ndn-cxx/util/scheduler.cpp
index 8a542c3..b8a9691 100644
--- a/ndn-cxx/util/scheduler.cpp
+++ b/ndn-cxx/util/scheduler.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-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -37,7 +37,7 @@
{
}
- NDN_CXX_NODISCARD time::nanoseconds
+ [[nodiscard]] time::nanoseconds
expiresFromNow() const
{
return std::max(expireTime - time::steady_clock::now(), 0_ns);
diff --git a/ndn-cxx/util/segmenter.hpp b/ndn-cxx/util/segmenter.hpp
index bfbf838..8ebd1aa 100644
--- a/ndn-cxx/util/segmenter.hpp
+++ b/ndn-cxx/util/segmenter.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).
*
@@ -50,7 +50,7 @@
* @param contentType The `ContentType` of created Data packets.
* @note A minimum of one Data packet is always returned, even if @p buffer is empty.
*/
- NDN_CXX_NODISCARD std::vector<std::shared_ptr<Data>>
+ [[nodiscard]] std::vector<std::shared_ptr<Data>>
segment(span<const uint8_t> buffer,
const Name& dataName,
size_t maxSegmentSize,
@@ -66,7 +66,7 @@
* @param contentType The `ContentType` of created Data packets.
* @note A minimum of one Data packet is always returned, even if @p input is empty.
*/
- NDN_CXX_NODISCARD std::vector<std::shared_ptr<Data>>
+ [[nodiscard]] std::vector<std::shared_ptr<Data>>
segment(std::istream& input,
const Name& dataName,
size_t maxSegmentSize,
diff --git a/ndn-cxx/util/string-helper.hpp b/ndn-cxx/util/string-helper.hpp
index 1149837..4447df4 100644
--- a/ndn-cxx/util/string-helper.hpp
+++ b/ndn-cxx/util/string-helper.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).
*
@@ -99,7 +99,7 @@
* Each octet of input is always converted to two hex characters (e.g., "00" for octet==0).
* The output string is a continuous sequence of hex characters without any whitespace separators.
*/
-NDN_CXX_NODISCARD std::string
+[[nodiscard]] std::string
toHex(span<const uint8_t> buffer, bool wantUpperCase = true);
/**
@@ -114,7 +114,7 @@
/**
* @brief Convert (the least significant nibble of) @p n to the corresponding hex character.
*/
-NDN_CXX_NODISCARD constexpr char
+[[nodiscard]] constexpr char
toHexChar(unsigned int n, bool wantUpperCase = true) noexcept
{
return wantUpperCase ?
@@ -125,7 +125,7 @@
/**
* @brief Convert the hex character @p c to an integer in [0, 15], or -1 if it's not a hex character.
*/
-NDN_CXX_NODISCARD constexpr int
+[[nodiscard]] constexpr int
fromHexChar(char c) noexcept
{
return (c >= '0' && c <= '9') ? int(c - '0') :
@@ -151,7 +151,7 @@
*
* @see RFC 3986 section 2
*/
-NDN_CXX_NODISCARD std::string
+[[nodiscard]] std::string
escape(const std::string& str);
void
@@ -171,7 +171,7 @@
*
* @see RFC 3986 section 2
*/
-NDN_CXX_NODISCARD std::string
+[[nodiscard]] std::string
unescape(const std::string& str);
void
diff --git a/tests/unit/security/pib/pib-data-fixture.hpp b/tests/unit/security/pib/pib-data-fixture.hpp
index 66e7fbf..64c8652 100644
--- a/tests/unit/security/pib/pib-data-fixture.hpp
+++ b/tests/unit/security/pib/pib-data-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).
*
@@ -35,10 +35,10 @@
public:
PibDataFixture();
- NDN_CXX_NODISCARD static shared_ptr<PibImpl>
+ [[nodiscard]] static shared_ptr<PibImpl>
makePibWithIdentity(const Name& idName);
- NDN_CXX_NODISCARD static shared_ptr<PibImpl>
+ [[nodiscard]] static shared_ptr<PibImpl>
makePibWithKey(const Name& keyName, span<const uint8_t> key);
public:
diff --git a/tests/unit/util/backports.t.cpp b/tests/unit/util/backports.t.cpp
deleted file mode 100644
index 2404d03..0000000
--- a/tests/unit/util/backports.t.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2020 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- */
-
-#include "ndn-cxx/util/backports.hpp"
-
-#include "tests/boost-test.hpp"
-
-namespace ndn {
-namespace tests {
-
-BOOST_AUTO_TEST_SUITE(Util)
-BOOST_AUTO_TEST_SUITE(TestBackports)
-
-BOOST_AUTO_TEST_CASE(Clamp)
-{
- int x = clamp(5, 1, 10);
- BOOST_CHECK_EQUAL(x, 5);
-
- x = clamp(-5, 1, 10);
- BOOST_CHECK_EQUAL(x, 1);
-
- x = clamp(15, 1, 10);
- BOOST_CHECK_EQUAL(x, 10);
-
- x = clamp(5, 10, 1, std::greater<int>());
- BOOST_CHECK_EQUAL(x, 5);
-
- x = clamp(-5, 10, 1, std::greater<int>());
- BOOST_CHECK_EQUAL(x, 1);
-
- x = clamp(15, 10, 1, std::greater<int>());
- BOOST_CHECK_EQUAL(x, 10);
-}
-
-BOOST_AUTO_TEST_SUITE_END() // TestBackports
-BOOST_AUTO_TEST_SUITE_END() // Util
-
-} // namespace tests
-} // namespace ndn