build: switch to C++17

Change-Id: I92039300ce845de0312dceccb94c128229ed60c4
This commit is contained in:
Davide Pesavento committed 2023-03-10 18:44:11 -05:00
1 parent 762548b15e
commit fcd3e44028
38 files changed
+119 -238

No files matched your search

+1 -1
View File
@@ -16,7 +16,7 @@ if [[ $ID_LIKE == *fedora* ]]; then
fi fi
CXX=${CXX:-g++} 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)" CXXFLAGS="-O2 -Wall -Wno-unneeded-internal-declaration -Wno-unused-const-variable $(pkg-config --cflags libndn-cxx $PCFILE)"
INCLUDEDIR="$(pkg-config --variable=includedir $PCFILE)"/$PROJ INCLUDEDIR="$(pkg-config --variable=includedir $PCFILE)"/$PROJ
+1 -1
View File
@@ -139,7 +139,7 @@ class GccBasicFlags(CompilerFlags):
""" """
def getGeneralFlags(self, conf): def getGeneralFlags(self, conf):
flags = super(GccBasicFlags, self).getGeneralFlags(conf) flags = super(GccBasicFlags, self).getGeneralFlags(conf)
flags['CXXFLAGS'] += ['-std=c++14'] flags['CXXFLAGS'] += ['-std=c++17']
if Utils.unversioned_sys_platform() != 'darwin': if Utils.unversioned_sys_platform() != 'darwin':
flags['LINKFLAGS'] += ['-fuse-ld=lld'] flags['LINKFLAGS'] += ['-fuse-ld=lld']
return flags return flags
+2 -2
View File
@@ -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) [![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) [![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) ![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 that can be used to write various NDN applications. The library is currently being
used by the following projects: used by the following projects:
+7 -7
View File
@@ -180,7 +180,7 @@ extended it to C++.
switch (condition) { switch (condition) {
case ABC: // 2 space indent case ABC: // 2 space indent
statements; // 4 space indent statements; // 4 space indent
NDN_CXX_FALLTHROUGH; [[fallthrough]];
case DEF: case DEF:
statements; statements;
@@ -211,7 +211,7 @@ extended it to C++.
// Correct style // Correct style
case A1: { case A1: {
statements; statements;
NDN_CXX_FALLTHROUGH; [[fallthrough]];
} }
// Incorrect style: braces should cover the entire case block // Incorrect style: braces should cover the entire case block
@@ -232,7 +232,7 @@ extended it to C++.
switch (condition) { switch (condition) {
case ABC: // no indent case ABC: // no indent
statements; // 2 space indent statements; // 2 space indent
NDN_CXX_FALLTHROUGH; [[fallthrough]];
case DEF: case DEF:
statements; statements;
@@ -243,11 +243,11 @@ extended it to C++.
break; break;
} }
The ``NDN_CXX_FALLTHROUGH`` annotation must be included whenever there is The ``[[fallthrough]]`` annotation must be included whenever there is a
a case without a break statement. Leaving the break out is a common error, 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. 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 Moreover, modern compilers will warn when a case that falls through is
explicitly annotated. not explicitly annotated.
1.11. A ``try-catch`` statement should have the following form: 1.11. A ``try-catch`` statement should have the following form:
+1 -1
View File
@@ -19,7 +19,7 @@ ndn-cxx: NDN C++ library with eXperimental eXtensions
release-notes release-notes
releases 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 that can be used to write various NDN applications. The library is currently being
used by the following projects: used by the following projects:
+4 -4
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -30,9 +30,9 @@
#include "ndn-cxx/detail/config.hpp" #include "ndn-cxx/detail/config.hpp"
// require C++14 // require C++17
#if __cplusplus < 201402L #if __cplusplus < 201703L
#error "ndn-cxx applications must be compiled using the C++14 standard (-std=c++14)" #error "ndn-cxx applications must be compiled using the C++17 standard (-std=c++17)"
#endif #endif
// ndn-cxx specific macros declared in this and other headers must have NDN_CXX_ prefix // ndn-cxx specific macros declared in this and other headers must have NDN_CXX_ prefix
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -162,7 +162,7 @@ public: // construction, assignment
* @return `true` and the parsed Block if parsing succeeds; otherwise `false` and an invalid Block * @return `true` and the parsed Block if parsing succeeds; otherwise `false` and an invalid Block
* @note This function does not throw upon decoding failure. * @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); fromBuffer(ConstBufferPtr buffer, size_t offset = 0);
/** @brief Try to parse Block from a byte range /** @brief Try to parse Block from a byte range
@@ -172,7 +172,7 @@ public: // construction, assignment
* @note This overload copies the TLV element octets to an internal buffer. * @note This overload copies the TLV element octets to an internal buffer.
* @note This function does not throw upon decoding failure. * @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); fromBuffer(span<const uint8_t> buffer);
/** @brief Parse Block from an input stream /** @brief Parse Block from an input stream
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -176,7 +176,7 @@ isCriticalType(uint32_t type) noexcept
* @return true if number was successfully read from input, false otherwise * @return true if number was successfully read from input, false otherwise
*/ */
template<typename Iterator> template<typename Iterator>
NDN_CXX_NODISCARD bool [[nodiscard]] bool
readVarNumber(Iterator& begin, Iterator end, uint64_t& number) noexcept; readVarNumber(Iterator& begin, Iterator end, uint64_t& number) noexcept;
/** /**
@@ -193,7 +193,7 @@ readVarNumber(Iterator& begin, Iterator end, uint64_t& number) noexcept;
* the TLV-TYPE is zero or larger than 2^32-1 (maximum allowed by the packet format). * the TLV-TYPE is zero or larger than 2^32-1 (maximum allowed by the packet format).
*/ */
template<typename Iterator> template<typename Iterator>
NDN_CXX_NODISCARD bool [[nodiscard]] bool
readType(Iterator& begin, Iterator end, uint32_t& type) noexcept; readType(Iterator& begin, Iterator end, uint32_t& type) noexcept;
/** /**
+4 -4
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -109,7 +109,7 @@ public: // consumer
void void
asyncRemovePendingInterest(detail::RecordId id) 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(); auto impl = w.lock();
if (impl != nullptr) { if (impl != nullptr) {
impl->m_pendingInterestTable.erase(id); impl->m_pendingInterestTable.erase(id);
@@ -195,7 +195,7 @@ public: // producer
void void
asyncUnsetInterestFilter(detail::RecordId id) 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(); auto impl = w.lock();
if (impl != nullptr) { if (impl != nullptr) {
impl->unsetInterestFilter(id); impl->unsetInterestFilter(id);
@@ -292,7 +292,7 @@ public: // prefix registration
const UnregisterPrefixSuccessCallback& onSuccess, const UnregisterPrefixSuccessCallback& onSuccess,
const UnregisterPrefixFailureCallback& onFailure) 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(); auto impl = w.lock();
if (impl != nullptr) { if (impl != nullptr) {
impl->unregisterPrefix(id, onSuccess, onFailure); impl->unregisterPrefix(id, onSuccess, onFailure);
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -173,7 +173,7 @@ public:
}); });
} }
NDN_CXX_NODISCARD bool [[nodiscard]] bool
empty() const noexcept empty() const noexcept
{ {
return m_container.empty(); return m_container.empty();
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -125,7 +125,7 @@ public:
/** /**
* \brief Get whether Interest loopback is allowed. * \brief Get whether Interest loopback is allowed.
*/ */
NDN_CXX_NODISCARD bool [[nodiscard]] bool
allowsLoopback() const noexcept allowsLoopback() const noexcept
{ {
return m_allowsLoopback; return m_allowsLoopback;
+2 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -758,8 +758,7 @@ operator<<(std::ostream& os, const Interest& interest)
auto printOne = [&] (const auto&... args) { auto printOne = [&] (const auto&... args) {
os << delim; os << delim;
delim = '&'; delim = '&';
using expand = int[]; (os << ... << args);
(void)expand{(os << args, 0)...}; // use a fold expression when we switch to C++17
}; };
if (interest.getCanBePrefix()) { if (interest.getCanBePrefix()) {
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -464,7 +464,7 @@ private:
Interest& Interest&
setSignatureValueInternal(Block sigValue); setSignatureValueInternal(Block sigValue);
NDN_CXX_NODISCARD shared_ptr<Buffer> [[nodiscard]] shared_ptr<Buffer>
computeParametersDigest() const; computeParametersDigest() const;
/** @brief Append a ParametersSha256DigestComponent to the Interest's name /** @brief Append a ParametersSha256DigestComponent to the Interest's name
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -71,7 +71,7 @@ public: // encode and decode
wireDecode(const Block& wire); wireDecode(const Block& wire);
public: // attributes public: // attributes
NDN_CXX_NODISCARD bool [[nodiscard]] bool
empty() const empty() const
{ {
return holds_alternative<monostate>(m_locator); return holds_alternative<monostate>(m_locator);
+5 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -61,7 +61,7 @@ public:
* \retval true packet has no field * \retval true packet has no field
* \retval false packet has one or more fields * \retval false packet has one or more fields
*/ */
NDN_CXX_NODISCARD bool [[nodiscard]] bool
empty() const empty() const
{ {
return m_wire.elements_size() == 0; return m_wire.elements_size() == 0;
@@ -73,7 +73,7 @@ public: // field access
* \details This is equivalent to count() > 0 * \details This is equivalent to count() > 0
*/ */
template<typename FIELD> template<typename FIELD>
NDN_CXX_NODISCARD bool [[nodiscard]] bool
has() const has() const
{ {
return count<FIELD>() > 0; return count<FIELD>() > 0;
@@ -83,7 +83,7 @@ public: // field access
* \brief Returns the number of occurrences of \c FIELD. * \brief Returns the number of occurrences of \c FIELD.
*/ */
template<typename FIELD> template<typename FIELD>
NDN_CXX_NODISCARD size_t [[nodiscard]] size_t
count() const count() const
{ {
return std::count_if(m_wire.elements_begin(), m_wire.elements_end(), return std::count_if(m_wire.elements_begin(), m_wire.elements_end(),
@@ -115,7 +115,7 @@ public: // field access
* \brief Returns the values of all occurrences of \c FIELD. * \brief Returns the values of all occurrences of \c FIELD.
*/ */
template<typename FIELD> template<typename FIELD>
NDN_CXX_NODISCARD std::vector<typename FIELD::ValueType> [[nodiscard]] std::vector<typename FIELD::ValueType>
list() const list() const
{ {
std::vector<typename FIELD::ValueType> output; std::vector<typename FIELD::ValueType> output;
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -79,7 +79,7 @@ public:
* *
* @throw tlv::Error @p discoveryInterestName is not valid * @throw tlv::Error @p discoveryInterestName is not valid
*/ */
NDN_CXX_NODISCARD Data [[nodiscard]] Data
makeData(Name discoveryInterestName, makeData(Name discoveryInterestName,
KeyChain& keyChain, KeyChain& keyChain,
const ndn::security::SigningInfo& si = security::SigningInfo(), const ndn::security::SigningInfo& si = security::SigningInfo(),
@@ -123,7 +123,7 @@ public: // static methods
* *
* @param name prefix of data collection * @param name prefix of data collection
*/ */
NDN_CXX_NODISCARD static Interest [[nodiscard]] static Interest
makeDiscoveryInterest(Name name); makeDiscoveryInterest(Name name);
private: private:
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -543,7 +543,7 @@ public: // commonly used TLV-TYPEs
} }
public: // comparison public: // comparison
NDN_CXX_NODISCARD bool [[nodiscard]] bool
empty() const noexcept empty() const noexcept
{ {
return value_size() == 0; return value_size() == 0;
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -142,7 +142,7 @@ public: // access
/** /**
* @brief Checks if the name is empty, i.e., has no components. * @brief Checks if the name is empty, i.e., has no components.
*/ */
NDN_CXX_NODISCARD bool [[nodiscard]] bool
empty() const noexcept empty() const noexcept
{ {
return m_wire.elements().empty(); return m_wire.elements().empty();
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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, * Arizona Board of Regents,
* Colorado State University, * Colorado State University,
* University Pierre & Marie Curie, Sorbonne University, * University Pierre & Marie Curie, Sorbonne University,
@@ -67,7 +67,7 @@ public:
FaceUri(const char* uri); FaceUri(const char* uri);
/// Exception-safe parsing. /// Exception-safe parsing.
NDN_CXX_NODISCARD bool [[nodiscard]] bool
parse(const std::string& uri); parse(const std::string& uri);
public: // scheme-specific construction public: // scheme-specific construction
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -92,7 +92,7 @@ public:
* @warning May return incomplete results if called before the * @warning May return incomplete results if called before the
* #onEnumerationCompleted signal has been emitted. * #onEnumerationCompleted signal has been emitted.
*/ */
NDN_CXX_NODISCARD std::vector<shared_ptr<const NetworkInterface>> [[nodiscard]] std::vector<shared_ptr<const NetworkInterface>>
listNetworkInterfaces() const; listNetworkInterfaces() const;
protected: protected:
+5 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -31,10 +31,10 @@ namespace ndn {
namespace security { namespace security {
namespace detail { namespace detail {
NDN_CXX_NODISCARD const EVP_MD* [[nodiscard]] const EVP_MD*
digestAlgorithmToEvpMd(DigestAlgorithm algo); digestAlgorithmToEvpMd(DigestAlgorithm algo);
NDN_CXX_NODISCARD int [[nodiscard]] int
getEvpPkeyType(const EVP_PKEY* key); getEvpPkeyType(const EVP_PKEY* key);
class EvpMdCtx : noncopyable class EvpMdCtx : noncopyable
@@ -86,10 +86,10 @@ public:
return m_bio; return m_bio;
} }
NDN_CXX_NODISCARD bool [[nodiscard]] bool
read(span<uint8_t> buf) const noexcept; read(span<uint8_t> buf) const noexcept;
NDN_CXX_NODISCARD bool [[nodiscard]] bool
write(span<const uint8_t> buf) noexcept; write(span<const uint8_t> buf) noexcept;
private: private:
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -114,13 +114,13 @@ KeyChain::getDefaultKeyParams()
class KeyChain::Locator class KeyChain::Locator
{ {
public: public:
NDN_CXX_NODISCARD bool [[nodiscard]] bool
empty() const empty() const
{ {
return scheme.empty(); return scheme.empty();
} }
NDN_CXX_NODISCARD std::string [[nodiscard]] std::string
canonical() const canonical() const
{ {
return scheme + ':' + location; return scheme + ':' + location;
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -121,7 +121,7 @@ public:
/** /**
* @brief Check whether the container is empty. * @brief Check whether the container is empty.
*/ */
NDN_CXX_NODISCARD bool [[nodiscard]] bool
empty() const noexcept empty() const noexcept
{ {
return m_certNames.empty(); return m_certNames.empty();
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -122,7 +122,7 @@ public:
/** /**
* @brief Check whether the container is empty. * @brief Check whether the container is empty.
*/ */
NDN_CXX_NODISCARD bool [[nodiscard]] bool
empty() const noexcept empty() const noexcept
{ {
return m_identityNames.empty(); return m_identityNames.empty();
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -122,7 +122,7 @@ public:
/** /**
* @brief Check whether the container is empty. * @brief Check whether the container is empty.
*/ */
NDN_CXX_NODISCARD bool [[nodiscard]] bool
empty() const noexcept empty() const noexcept
{ {
return m_keyNames.empty(); return m_keyNames.empty();
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -155,7 +155,7 @@ public: // key management
* *
* @return True if the TPM was unlocked. * @return True if the TPM was unlocked.
*/ */
NDN_CXX_NODISCARD virtual bool [[nodiscard]] virtual bool
unlockTpm(const char* pw, size_t pwLen) const; unlockTpm(const char* pw, size_t pwLen) const;
protected: // helper methods protected: // helper methods
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -117,7 +117,7 @@ public:
* @retval false the signature is not valid * @retval false the signature is not valid
* @retval indeterminate the key does not exist * @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, verify(const InputBuffers& bufs, span<const uint8_t> sig, const Name& keyName,
DigestAlgorithm digestAlgorithm) const; DigestAlgorithm digestAlgorithm) const;
@@ -156,7 +156,7 @@ public: // Management
* @param password The password to unlock the TPM. * @param password The password to unlock the TPM.
* @param passwordLength The password size. * @param passwordLength The password size.
*/ */
NDN_CXX_NODISCARD bool [[nodiscard]] bool
unlockTpm(const char* password, size_t passwordLength) const; unlockTpm(const char* password, size_t passwordLength) const;
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // operations accessible only by KeyChain NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // operations accessible only by KeyChain
+13 -13
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -51,21 +51,21 @@ class Certificate;
/** /**
* @brief Verify @p blobs using @p key against @p sig. * @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); verifySignature(const InputBuffers& blobs, span<const uint8_t> sig, const transform::PublicKey& key);
/** /**
* @brief Verify @p blobs using @p key against @p sig. * @brief Verify @p blobs using @p key against @p sig.
* @note @p key must be a public key in PKCS #8 format. * @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); verifySignature(const InputBuffers& blobs, span<const uint8_t> sig, span<const uint8_t> key);
/** /**
* @brief Verify @p data using @p key. * @brief Verify @p data using @p key.
* @note @p key must be a public key in PKCS #8 format. * @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); verifySignature(const Data& data, span<const uint8_t> key);
/** /**
@@ -73,33 +73,33 @@ verifySignature(const Data& data, span<const uint8_t> key);
* @note @p key must be a public key in PKCS #8 format. * @note @p key must be a public key in PKCS #8 format.
* @note This method verifies only signature of the signed interest. * @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); verifySignature(const Interest& interest, span<const uint8_t> key);
/** /**
* @brief Verify @p data using @p key. * @brief Verify @p data using @p key.
*/ */
NDN_CXX_NODISCARD bool [[nodiscard]] bool
verifySignature(const Data& data, const transform::PublicKey& key); verifySignature(const Data& data, const transform::PublicKey& key);
/** /**
* @brief Verify @p interest using @p key. * @brief Verify @p interest using @p key.
* @note This method verifies only signature of the signed interest. * @note This method verifies only signature of the signed interest.
*/ */
NDN_CXX_NODISCARD bool [[nodiscard]] bool
verifySignature(const Interest& interest, const transform::PublicKey& key); verifySignature(const Interest& interest, const transform::PublicKey& key);
/** /**
* @brief Verify @p data using @p key. * @brief Verify @p data using @p key.
*/ */
NDN_CXX_NODISCARD bool [[nodiscard]] bool
verifySignature(const Data& data, const pib::Key& key); verifySignature(const Data& data, const pib::Key& key);
/** /**
* @brief Verify @p interest using @p key. * @brief Verify @p interest using @p key.
* @note This method verifies only signature of the signed interest. * @note This method verifies only signature of the signed interest.
*/ */
NDN_CXX_NODISCARD bool [[nodiscard]] bool
verifySignature(const Interest& interest, const pib::Key& key); verifySignature(const Interest& interest, const pib::Key& key);
/** /**
@@ -107,7 +107,7 @@ verifySignature(const Interest& interest, const pib::Key& key);
* *
* If @p cert is nullopt, @p data assumed to be self-verifiable (with digest or attributes) * 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); verifySignature(const Data& data, const optional<Certificate>& cert);
/** /**
@@ -116,13 +116,13 @@ verifySignature(const Data& data, const optional<Certificate>& cert);
* *
* If @p cert is nullptr, @p interest assumed to be self-verifiable (with digest or attributes) * 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); verifySignature(const Interest& interest, const optional<Certificate>& cert);
/** /**
* @brief Verify @p data using @p tpm and @p keyName with the @p digestAlgorithm. * @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, verifySignature(const Data& data, const tpm::Tpm& tpm, const Name& keyName,
DigestAlgorithm digestAlgorithm); DigestAlgorithm digestAlgorithm);
@@ -130,7 +130,7 @@ verifySignature(const Data& data, const tpm::Tpm& tpm, const Name& keyName,
* @brief Verify @p interest using @p tpm and @p keyName with the @p digestAlgorithm. * @brief Verify @p interest using @p tpm and @p keyName with the @p digestAlgorithm.
* @note This method verifies only signature of the signed interest. * @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, verifySignature(const Interest& interest, const tpm::Tpm& tpm, const Name& keyName,
DigestAlgorithm digestAlgorithm); DigestAlgorithm digestAlgorithm);
+4 -66
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * 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/gcc.h>
#include <boost/predef/compiler/visualc.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 #ifndef NDN_CXX_HAVE_STD_TO_STRING
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#endif #endif
#include <utility>
namespace ndn { namespace ndn {
// //
@@ -89,30 +51,6 @@ to_string(const T& val)
} }
#endif // NDN_CXX_HAVE_STD_TO_STRING #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 // https://wg21.link/P1682
// std::to_underlying() (C++23) // std::to_underlying() (C++23)
@@ -121,7 +59,7 @@ clamp(const T& v, const T& lo, const T& hi)
using std::to_underlying; using std::to_underlying;
#else #else
template<typename T> template<typename T>
NDN_CXX_NODISCARD constexpr std::underlying_type_t<T> [[nodiscard]] constexpr std::underlying_type_t<T>
to_underlying(T val) noexcept to_underlying(T val) noexcept
{ {
// instantiating underlying_type with a non-enum type is UB before C++20 // instantiating underlying_type with a non-enum type is UB before C++20
+3 -3
View File
@@ -50,7 +50,7 @@ public:
/** /**
* \brief Get list of all registered logger names. * \brief Get list of all registered logger names.
*/ */
NDN_CXX_NODISCARD static std::set<std::string> [[nodiscard]] static std::set<std::string>
getLoggerNames(); getLoggerNames();
/** \brief Set severity level. /** \brief Set severity level.
@@ -118,7 +118,7 @@ public:
/** /**
* \brief Create stream log destination using default formatting. * \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); makeDefaultStreamDestination(shared_ptr<std::ostream> os, bool wantAutoFlush = true);
private: private:
@@ -130,7 +130,7 @@ private:
void void
registerLoggerNameImpl(std::string name); registerLoggerNameImpl(std::string name);
NDN_CXX_NODISCARD std::set<std::string> [[nodiscard]] std::set<std::string>
getLoggerNamesImpl() const; getLoggerNamesImpl() const;
/** /**
+7 -6
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * 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. * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
*/ */
/** \file /**
* \brief Backport of ostream_joiner from the Library Fundamentals v2 TS * \file
* \sa https://en.cppreference.com/w/cpp/experimental/ostream_joiner * \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 #ifndef NDN_CXX_UTIL_OSTREAM_JOINER_HPP
#define 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> # include <experimental/iterator>
# if __cpp_lib_experimental_ostream_joiner >= 201411 # if __cpp_lib_experimental_ostream_joiner >= 201411
# define NDN_CXX_HAVE_EXPERIMENTAL_OSTREAM_JOINER # define NDN_CXX_HAVE_EXPERIMENTAL_OSTREAM_JOINER
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -206,7 +206,7 @@ RegexTopMatcher::convertSpecialChar(const std::string& str)
case '^': case '^':
case '$': case '$':
newStr.push_back('\\'); newStr.push_back('\\');
NDN_CXX_FALLTHROUGH; [[fallthrough]];
default: default:
newStr.push_back(c); newStr.push_back(c);
break; break;
+5 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -59,15 +59,15 @@ RttEstimator::addMeasurement(time::nanoseconds rtt, size_t nExpectedSamples)
beta * time::abs(m_sRtt - rtt)); beta * time::abs(m_sRtt - rtt));
m_sRtt = time::duration_cast<time::nanoseconds>((1 - alpha) * m_sRtt + alpha * 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_rto = std::clamp(m_sRtt + m_options->k * m_rttVar,
m_options->minRto, m_options->maxRto); m_options->minRto, m_options->maxRto);
} }
void void
RttEstimator::backoffRto() RttEstimator::backoffRto()
{ {
m_rto = clamp(m_rto * m_options->rtoBackoffMultiplier, m_rto = std::clamp(m_rto * m_options->rtoBackoffMultiplier,
m_options->minRto, m_options->maxRto); m_options->minRto, m_options->maxRto);
} }
void void
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -37,7 +37,7 @@ public:
{ {
} }
NDN_CXX_NODISCARD time::nanoseconds [[nodiscard]] time::nanoseconds
expiresFromNow() const expiresFromNow() const
{ {
return std::max(expireTime - time::steady_clock::now(), 0_ns); return std::max(expireTime - time::steady_clock::now(), 0_ns);
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -50,7 +50,7 @@ public:
* @param contentType The `ContentType` of created Data packets. * @param contentType The `ContentType` of created Data packets.
* @note A minimum of one Data packet is always returned, even if @p buffer is empty. * @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, segment(span<const uint8_t> buffer,
const Name& dataName, const Name& dataName,
size_t maxSegmentSize, size_t maxSegmentSize,
@@ -66,7 +66,7 @@ public:
* @param contentType The `ContentType` of created Data packets. * @param contentType The `ContentType` of created Data packets.
* @note A minimum of one Data packet is always returned, even if @p input is empty. * @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, segment(std::istream& input,
const Name& dataName, const Name& dataName,
size_t maxSegmentSize, size_t maxSegmentSize,
+6 -6
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -99,7 +99,7 @@ private:
* Each octet of input is always converted to two hex characters (e.g., "00" for octet==0). * 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. * 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); toHex(span<const uint8_t> buffer, bool wantUpperCase = true);
/** /**
@@ -114,7 +114,7 @@ fromHex(const std::string& hexString);
/** /**
* @brief Convert (the least significant nibble of) @p n to the corresponding hex character. * @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 toHexChar(unsigned int n, bool wantUpperCase = true) noexcept
{ {
return wantUpperCase ? return wantUpperCase ?
@@ -125,7 +125,7 @@ toHexChar(unsigned int n, bool wantUpperCase = true) noexcept
/** /**
* @brief Convert the hex character @p c to an integer in [0, 15], or -1 if it's not a hex character. * @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 fromHexChar(char c) noexcept
{ {
return (c >= '0' && c <= '9') ? int(c - '0') : return (c >= '0' && c <= '9') ? int(c - '0') :
@@ -151,7 +151,7 @@ fromHexChar(char c) noexcept
* *
* @see RFC 3986 section 2 * @see RFC 3986 section 2
*/ */
NDN_CXX_NODISCARD std::string [[nodiscard]] std::string
escape(const std::string& str); escape(const std::string& str);
void void
@@ -171,7 +171,7 @@ escape(std::ostream& os, const char* str, size_t len);
* *
* @see RFC 3986 section 2 * @see RFC 3986 section 2
*/ */
NDN_CXX_NODISCARD std::string [[nodiscard]] std::string
unescape(const std::string& str); unescape(const std::string& str);
void void
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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). * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
* *
@@ -35,10 +35,10 @@ class PibDataFixture
public: public:
PibDataFixture(); PibDataFixture();
NDN_CXX_NODISCARD static shared_ptr<PibImpl> [[nodiscard]] static shared_ptr<PibImpl>
makePibWithIdentity(const Name& idName); 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); makePibWithKey(const Name& keyName, span<const uint8_t> key);
public: public:
-57
View File
@@ -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