Use Boost.Operators in more places
Change-Id: I7024c3e7d4c30c99ec7a895d484f227cb60fb356
diff --git a/ndn-cxx/encoding/block.hpp b/ndn-cxx/encoding/block.hpp
index 0aa4f7f..e0d21b8 100644
--- a/ndn-cxx/encoding/block.hpp
+++ b/ndn-cxx/encoding/block.hpp
@@ -29,6 +29,8 @@
#include "ndn-cxx/encoding/tlv.hpp"
#include "ndn-cxx/util/span.hpp"
+#include <boost/operators.hpp>
+
namespace boost::asio {
class const_buffer;
} // namespace boost::asio
@@ -39,7 +41,7 @@
* @brief Represents a TLV element of the NDN packet format.
* @sa https://docs.named-data.net/NDN-packet-spec/0.3/tlv.html
*/
-class Block
+class Block : private boost::equality_comparable<Block>
{
public:
using value_type = Buffer::value_type;
@@ -463,13 +465,6 @@
*/
operator boost::asio::const_buffer() const;
-protected:
- /**
- * @brief Returns whether this Block has the same TLV-TYPE/TLV-LENGTH/TLV-VALUE as @p other.
- */
- bool
- equals(const Block& other) const noexcept;
-
private:
/**
* @brief Estimate Block size as if sub-elements are encoded into TLV-VALUE.
@@ -491,12 +486,19 @@
size_t
encode(EncodingBuffer& encoder);
+ /**
+ * @brief Returns whether this Block has the same TLV-TYPE/TLV-LENGTH/TLV-VALUE as @p other.
+ */
+ bool
+ equals(const Block& other) const noexcept;
+
void
print(std::ostream& os) const;
private: // non-member operators
// NOTE: the following "hidden friend" operators are available via
// argument-dependent lookup only and must be defined inline.
+ // boost::equality_comparable provides != operator.
/**
* @brief Compare whether two Blocks have the same TLV-TYPE, TLV-LENGTH, and TLV-VALUE.
@@ -507,12 +509,6 @@
return lhs.equals(rhs);
}
- friend bool
- operator!=(const Block& lhs, const Block& rhs) noexcept
- {
- return !lhs.equals(rhs);
- }
-
/**
* @brief Print @p block to @p os.
*
diff --git a/ndn-cxx/encoding/encoder.hpp b/ndn-cxx/encoding/encoder.hpp
index 1d45314..3df1f48 100644
--- a/ndn-cxx/encoding/encoder.hpp
+++ b/ndn-cxx/encoding/encoder.hpp
@@ -252,7 +252,7 @@
Encoder::prependRange(Iterator first, Iterator last)
{
using ValueType = typename std::iterator_traits<Iterator>::value_type;
- static_assert(sizeof(ValueType) == 1 && !std::is_same_v<ValueType, bool>, "");
+ static_assert(sizeof(ValueType) == 1 && !std::is_same_v<ValueType, bool>);
size_t length = std::distance(first, last);
reserveFront(length);
@@ -267,7 +267,7 @@
Encoder::appendRange(Iterator first, Iterator last)
{
using ValueType = typename std::iterator_traits<Iterator>::value_type;
- static_assert(sizeof(ValueType) == 1 && !std::is_same_v<ValueType, bool>, "");
+ static_assert(sizeof(ValueType) == 1 && !std::is_same_v<ValueType, bool>);
size_t length = std::distance(first, last);
reserveBack(length);
diff --git a/ndn-cxx/encoding/nfd-constants.cpp b/ndn-cxx/encoding/nfd-constants.cpp
index c6f5a58..ede579e 100644
--- a/ndn-cxx/encoding/nfd-constants.cpp
+++ b/ndn-cxx/encoding/nfd-constants.cpp
@@ -121,8 +121,8 @@
routeOrigin = ROUTE_ORIGIN_STATIC;
else {
// To reject negative numbers, we parse as a wider signed type, and compare with the range.
- static_assert(std::numeric_limits<std::underlying_type_t<RouteOrigin>>::max() <=
- std::numeric_limits<int>::max(), "");
+ using RouteOriginUnderlyingType = std::underlying_type_t<RouteOrigin>;
+ static_assert(std::numeric_limits<RouteOriginUnderlyingType>::max() <= std::numeric_limits<int>::max());
int v = -1;
try {
@@ -131,8 +131,8 @@
catch (const boost::bad_lexical_cast&) {
}
- if (v >= std::numeric_limits<std::underlying_type_t<RouteOrigin>>::min() &&
- v <= std::numeric_limits<std::underlying_type_t<RouteOrigin>>::max()) {
+ if (v >= std::numeric_limits<RouteOriginUnderlyingType>::min() &&
+ v <= std::numeric_limits<RouteOriginUnderlyingType>::max()) {
routeOrigin = static_cast<RouteOrigin>(v);
}
else {
diff --git a/ndn-cxx/impl/common-pch.hpp b/ndn-cxx/impl/common-pch.hpp
index c7fcd43..adc09cd 100644
--- a/ndn-cxx/impl/common-pch.hpp
+++ b/ndn-cxx/impl/common-pch.hpp
@@ -55,6 +55,7 @@
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/sequenced_index.hpp>
+#include <boost/operators.hpp>
#include <boost/system/error_code.hpp>
#endif // NDN_CXX_IMPL_COMMON_PCH_HPP
diff --git a/ndn-cxx/ims/in-memory-storage.cpp b/ndn-cxx/ims/in-memory-storage.cpp
index 7115685..36ccb08 100644
--- a/ndn-cxx/ims/in-memory-storage.cpp
+++ b/ndn-cxx/ims/in-memory-storage.cpp
@@ -27,14 +27,6 @@
constexpr size_t MIN_CAPACITY = 16;
constexpr time::milliseconds ZERO_WINDOW = 0_ms;
-InMemoryStorage::const_iterator::const_iterator(const Data* ptr, const Cache* cache,
- Cache::index<byFullName>::type::iterator it)
- : m_ptr(ptr)
- , m_cache(cache)
- , m_it(it)
-{
-}
-
InMemoryStorage::const_iterator&
InMemoryStorage::const_iterator::operator++()
{
@@ -45,42 +37,9 @@
else {
m_ptr = nullptr;
}
-
return *this;
}
-InMemoryStorage::const_iterator
-InMemoryStorage::const_iterator::operator++(int)
-{
- InMemoryStorage::const_iterator i(*this);
- this->operator++();
- return i;
-}
-
-InMemoryStorage::const_iterator::reference
-InMemoryStorage::const_iterator::operator*()
-{
- return *m_ptr;
-}
-
-InMemoryStorage::const_iterator::pointer
-InMemoryStorage::const_iterator::operator->()
-{
- return m_ptr;
-}
-
-bool
-InMemoryStorage::const_iterator::operator==(const const_iterator& rhs)
-{
- return m_it == rhs.m_it;
-}
-
-bool
-InMemoryStorage::const_iterator::operator!=(const const_iterator& rhs)
-{
- return m_it != rhs.m_it;
-}
-
InMemoryStorage::InMemoryStorage(size_t limit)
: m_limit(limit)
, m_nPackets(0)
diff --git a/ndn-cxx/ims/in-memory-storage.hpp b/ndn-cxx/ims/in-memory-storage.hpp
index 22cd3b5..3096542 100644
--- a/ndn-cxx/ims/in-memory-storage.hpp
+++ b/ndn-cxx/ims/in-memory-storage.hpp
@@ -24,7 +24,6 @@
#include "ndn-cxx/ims/in-memory-storage-entry.hpp"
-#include <iterator>
#include <limits>
#include <stack>
@@ -58,39 +57,35 @@
>
>;
- /** @brief Represents a self-defined const_iterator for the in-memory storage.
- *
- * @note Don't try to instantiate this class directly, use InMemoryStorage::begin() instead.
+ /**
+ * @brief Represents a const_iterator for the in-memory storage.
+ * @note Do not instantiate this class directly, use InMemoryStorage::begin() instead.
*/
- class const_iterator
+ class const_iterator : public boost::forward_iterator_helper<const_iterator, const Data>
{
public:
- using iterator_category = std::input_iterator_tag;
- using value_type = const Data;
- using difference_type = std::ptrdiff_t;
- using pointer = value_type*;
- using reference = value_type&;
-
const_iterator(const Data* ptr, const Cache* cache,
- Cache::index<byFullName>::type::iterator it);
+ Cache::index<byFullName>::type::iterator it) noexcept
+ : m_ptr(ptr)
+ , m_cache(cache)
+ , m_it(it)
+ {
+ }
+
+ reference
+ operator*() const noexcept
+ {
+ return *m_ptr;
+ }
const_iterator&
operator++();
- const_iterator
- operator++(int);
-
- reference
- operator*();
-
- pointer
- operator->();
-
- bool
- operator==(const const_iterator& rhs);
-
- bool
- operator!=(const const_iterator& rhs);
+ friend bool
+ operator==(const const_iterator& lhs, const const_iterator& rhs) noexcept
+ {
+ return lhs.m_it == rhs.m_it;
+ }
private:
const Data* m_ptr;
diff --git a/ndn-cxx/interest.hpp b/ndn-cxx/interest.hpp
index 5ca7924..7b817ab 100644
--- a/ndn-cxx/interest.hpp
+++ b/ndn-cxx/interest.hpp
@@ -55,10 +55,8 @@
using tlv::Error::Error;
};
- class Nonce final : public std::array<uint8_t, 4>
+ class Nonce final : public std::array<uint8_t, 4>, private boost::equality_comparable<Nonce>
{
- using Base = std::array<uint8_t, 4>;
-
public:
Nonce() = default;
@@ -80,17 +78,12 @@
private: // non-member operators
// NOTE: the following "hidden friend" operators are available via
// argument-dependent lookup only and must be defined inline.
+ // boost::equality_comparable provides != operator.
friend bool
operator==(const Nonce& lhs, const Nonce& rhs) noexcept
{
- return static_cast<const Base&>(lhs) == static_cast<const Base&>(rhs);
- }
-
- friend bool
- operator!=(const Nonce& lhs, const Nonce& rhs) noexcept
- {
- return static_cast<const Base&>(lhs) != static_cast<const Base&>(rhs);
+ return std::equal(lhs.begin(), lhs.end(), rhs.begin());
}
friend std::ostream&
diff --git a/ndn-cxx/key-locator.cpp b/ndn-cxx/key-locator.cpp
index 03fae6b..78f55c0 100644
--- a/ndn-cxx/key-locator.cpp
+++ b/ndn-cxx/key-locator.cpp
@@ -50,12 +50,12 @@
size_t totalLength = 0;
- auto visitor = boost::hana::overload(
+ std::visit(boost::hana::overload(
[] (std::monostate) {}, // nothing to encode, TLV-VALUE is empty
[&] (const Name& name) { totalLength += name.wireEncode(encoder); },
[&] (const Block& digest) { totalLength += prependBlock(encoder, digest); },
- [] (uint32_t type) { NDN_THROW(Error("Unsupported KeyLocator type " + to_string(type))); });
- visit(visitor, m_locator);
+ [] (uint32_t type) { NDN_THROW(Error("Unsupported KeyLocator type " + to_string(type))); }),
+ m_locator);
totalLength += encoder.prependVarNumber(totalLength);
totalLength += encoder.prependVarNumber(tlv::KeyLocator);
@@ -183,10 +183,10 @@
return *this;
}
-std::ostream&
-operator<<(std::ostream& os, const KeyLocator& keyLocator)
+void
+KeyLocator::print(std::ostream& os) const
{
- auto visitor = boost::hana::overload(
+ std::visit(boost::hana::overload(
[&] (std::monostate) {
os << "None";
},
@@ -202,9 +202,8 @@
},
[&] (uint32_t type) {
os << "Unknown(" << type << ")";
- });
- visit(visitor, keyLocator.m_locator);
- return os;
+ }),
+ m_locator);
}
} // namespace ndn
diff --git a/ndn-cxx/key-locator.hpp b/ndn-cxx/key-locator.hpp
index 4c32261..7603753 100644
--- a/ndn-cxx/key-locator.hpp
+++ b/ndn-cxx/key-locator.hpp
@@ -28,7 +28,7 @@
namespace ndn {
-class KeyLocator
+class KeyLocator : private boost::equality_comparable<KeyLocator>
{
public:
class Error : public tlv::Error
@@ -124,9 +124,14 @@
KeyLocator&
setKeyDigest(const ConstBufferPtr& keyDigest);
+private:
+ void
+ print(std::ostream& os) const;
+
private: // non-member operators
// NOTE: the following "hidden friend" operators are available via
// argument-dependent lookup only and must be defined inline.
+ // boost::equality_comparable provides != operator.
friend bool
operator==(const KeyLocator& lhs, const KeyLocator& rhs)
@@ -134,10 +139,11 @@
return lhs.m_locator == rhs.m_locator;
}
- friend bool
- operator!=(const KeyLocator& lhs, const KeyLocator& rhs)
+ friend std::ostream&
+ operator<<(std::ostream& os, const KeyLocator& kl)
{
- return lhs.m_locator != rhs.m_locator;
+ kl.print(os);
+ return os;
}
private:
@@ -148,15 +154,10 @@
std::variant<std::monostate, Name, Block, uint32_t> m_locator;
mutable Block m_wire;
-
- friend std::ostream& operator<<(std::ostream&, const KeyLocator&);
};
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(KeyLocator);
-std::ostream&
-operator<<(std::ostream& os, const KeyLocator& keyLocator);
-
} // namespace ndn
#endif // NDN_CXX_KEY_LOCATOR_HPP
diff --git a/ndn-cxx/lp/field.hpp b/ndn-cxx/lp/field.hpp
index 3d72fda..741cb59 100644
--- a/ndn-cxx/lp/field.hpp
+++ b/ndn-cxx/lp/field.hpp
@@ -51,10 +51,10 @@
template<typename X>
struct Field
{
- static_assert(std::is_same_v<typename X::TlvType::value_type, uint32_t>, "");
- static_assert(std::is_same_v<typename X::IsRepeatable::value_type, bool>, "");
- static_assert(std::is_default_constructible_v<typename X::ValueType>, "");
- static_assert(std::is_copy_constructible_v<typename X::ValueType>, "");
+ static_assert(std::is_same_v<typename X::TlvType::value_type, uint32_t>);
+ static_assert(std::is_same_v<typename X::IsRepeatable::value_type, bool>);
+ static_assert(std::is_default_constructible_v<typename X::ValueType>);
+ static_assert(std::is_copy_constructible_v<typename X::ValueType>);
BOOST_CONCEPT_USAGE(Field)
{
diff --git a/ndn-cxx/metadata-object.cpp b/ndn-cxx/metadata-object.cpp
index 69db187..03a0b3e 100644
--- a/ndn-cxx/metadata-object.cpp
+++ b/ndn-cxx/metadata-object.cpp
@@ -25,9 +25,6 @@
namespace ndn {
-static_assert(std::is_convertible_v<MetadataObject::Error*, tlv::Error*>,
- "MetadataObject::Error must inherit from tlv::Error");
-
MetadataObject::MetadataObject() = default;
MetadataObject::MetadataObject(const Data& data)
diff --git a/ndn-cxx/name-component.hpp b/ndn-cxx/name-component.hpp
index 5870bb8..7bc90e8 100644
--- a/ndn-cxx/name-component.hpp
+++ b/ndn-cxx/name-component.hpp
@@ -109,7 +109,7 @@
* or, if it is an `ImplicitSha256DigestComponent` or a `ParametersSha256DigestComponent`,
* its TLV-LENGTH is not 32.
*/
-class Component : public Block
+class Component : public Block, private boost::less_than_comparable<Component>
{
public:
class Error : public Block::Error
@@ -482,23 +482,12 @@
}
/**
- * @brief Check whether this is the same component as @p other.
- * @param other The name component to compare with
- * @return true if the components are equal, false otherwise.
- */
- bool
- equals(const Component& other) const noexcept
- {
- return Block::equals(other);
- }
-
- /**
- * @brief Compare this to the other Component using NDN canonical ordering.
+ * @brief Compare this component to @p other using NDN canonical ordering.
*
- * @param other The other Component to compare with.
- * @retval negative this comes before other in canonical ordering
- * @retval zero this equals other
- * @retval positive this comes after other in canonical ordering
+ * @param other The name component to compare with.
+ * @retval negative This component comes before @p other in canonical ordering
+ * @retval zero This component equals @p other
+ * @retval positive This component comes after @p other in canonical ordering
*
* @sa https://docs.named-data.net/NDN-packet-spec/0.3/name.html#canonical-order
*/
@@ -543,18 +532,8 @@
private: // non-member operators
// NOTE: the following "hidden friend" operators are available via
// argument-dependent lookup only and must be defined inline.
-
- friend bool
- operator==(const Component& lhs, const Component& rhs) noexcept
- {
- return lhs.equals(rhs);
- }
-
- friend bool
- operator!=(const Component& lhs, const Component& rhs) noexcept
- {
- return !lhs.equals(rhs);
- }
+ // Block provides == and != operators.
+ // boost::less_than_comparable provides <=, >=, and > operators.
friend bool
operator<(const Component& lhs, const Component& rhs)
@@ -562,24 +541,6 @@
return lhs.compare(rhs) < 0;
}
- friend bool
- operator<=(const Component& lhs, const Component& rhs)
- {
- return lhs.compare(rhs) <= 0;
- }
-
- friend bool
- operator>(const Component& lhs, const Component& rhs)
- {
- return lhs.compare(rhs) > 0;
- }
-
- friend bool
- operator>=(const Component& lhs, const Component& rhs)
- {
- return lhs.compare(rhs) >= 0;
- }
-
friend std::ostream&
operator<<(std::ostream& os, const Component& component)
{
@@ -589,7 +550,7 @@
// !!! NOTE TO IMPLEMENTOR !!!
//
- // This class MUST NOT contain any data fields.
+ // This class MUST NOT contain any non-static data members.
// Block can be reinterpret_cast'ed as Component type.
};
diff --git a/ndn-cxx/name.hpp b/ndn-cxx/name.hpp
index 9968e5c..ad68c33 100644
--- a/ndn-cxx/name.hpp
+++ b/ndn-cxx/name.hpp
@@ -41,7 +41,7 @@
* @brief Represents an absolute name.
* @sa https://docs.named-data.net/NDN-packet-spec/0.3/name.html
*/
-class Name
+class Name : private boost::totally_ordered<Name>
{
public: // nested types
using Error = name::Component::Error;
@@ -646,6 +646,7 @@
private: // non-member operators
// NOTE: the following "hidden friend" operators are available via
// argument-dependent lookup only and must be defined inline.
+ // boost::totally_ordered provides !=, <=, >=, and > operators.
friend bool
operator==(const Name& lhs, const Name& rhs) noexcept
@@ -654,35 +655,11 @@
}
friend bool
- operator!=(const Name& lhs, const Name& rhs) noexcept
- {
- return !lhs.equals(rhs);
- }
-
- friend bool
operator<(const Name& lhs, const Name& rhs)
{
return lhs.compare(rhs) < 0;
}
- friend bool
- operator<=(const Name& lhs, const Name& rhs)
- {
- return lhs.compare(rhs) <= 0;
- }
-
- friend bool
- operator>(const Name& lhs, const Name& rhs)
- {
- return lhs.compare(rhs) > 0;
- }
-
- friend bool
- operator>=(const Name& lhs, const Name& rhs)
- {
- return lhs.compare(rhs) >= 0;
- }
-
/**
* @brief Print the URI representation of a name.
* @sa https://docs.named-data.net/NDN-packet-spec/0.3/name.html#ndn-uri-scheme
diff --git a/ndn-cxx/net/face-uri.cpp b/ndn-cxx/net/face-uri.cpp
index 0a40b5a..da5905f 100644
--- a/ndn-cxx/net/face-uri.cpp
+++ b/ndn-cxx/net/face-uri.cpp
@@ -181,25 +181,24 @@
FaceUri::toString() const
{
std::ostringstream os;
- os << *this;
+ print(os);
return os.str();
}
-std::ostream&
-operator<<(std::ostream& os, const FaceUri& uri)
+void
+FaceUri::print(std::ostream& os) const
{
- os << uri.m_scheme << "://";
- if (uri.m_isV6) {
- os << "[" << uri.m_host << "]";
+ os << m_scheme << "://";
+ if (m_isV6) {
+ os << "[" << m_host << "]";
}
else {
- os << uri.m_host;
+ os << m_host;
}
- if (!uri.m_port.empty()) {
- os << ":" << uri.m_port;
+ if (!m_port.empty()) {
+ os << ":" << m_port;
}
- os << uri.m_path;
- return os;
+ os << m_path;
}
diff --git a/ndn-cxx/net/face-uri.hpp b/ndn-cxx/net/face-uri.hpp
index aab2597..2adbc38 100644
--- a/ndn-cxx/net/face-uri.hpp
+++ b/ndn-cxx/net/face-uri.hpp
@@ -178,13 +178,17 @@
boost::asio::io_service& io,
time::nanoseconds timeout) const;
+private:
+ void
+ print(std::ostream& os) const;
+
private: // non-member operators
// NOTE: the following "hidden friend" operators are available via
// argument-dependent lookup only and must be defined inline.
// boost::totally_ordered provides !=, <=, >=, and > operators.
friend bool
- operator==(const FaceUri& lhs, const FaceUri& rhs)
+ operator==(const FaceUri& lhs, const FaceUri& rhs) noexcept
{
return lhs.m_isV6 == rhs.m_isV6 &&
lhs.m_scheme == rhs.m_scheme &&
@@ -194,25 +198,27 @@
}
friend bool
- operator<(const FaceUri& lhs, const FaceUri& rhs)
+ operator<(const FaceUri& lhs, const FaceUri& rhs) noexcept
{
return std::tie(lhs.m_scheme, lhs.m_isV6, lhs.m_host, lhs.m_port, lhs.m_path) <
std::tie(rhs.m_scheme, rhs.m_isV6, rhs.m_host, rhs.m_port, rhs.m_path);
}
+ friend std::ostream&
+ operator<<(std::ostream& os, const FaceUri& uri)
+ {
+ uri.print(os);
+ return os;
+ }
+
private:
std::string m_scheme;
std::string m_host;
std::string m_port;
std::string m_path;
bool m_isV6 = false; ///< whether to add [] around host when converting to string representation
-
- friend std::ostream& operator<<(std::ostream& os, const FaceUri& uri);
};
-std::ostream&
-operator<<(std::ostream& os, const FaceUri& uri);
-
} // namespace ndn
#endif // NDN_CXX_NET_FACE_URI_HPP
diff --git a/ndn-cxx/net/impl/netlink-socket.cpp b/ndn-cxx/net/impl/netlink-socket.cpp
index b3f59f7..706cc6d 100644
--- a/ndn-cxx/net/impl/netlink-socket.cpp
+++ b/ndn-cxx/net/impl/netlink-socket.cpp
@@ -366,7 +366,7 @@
{
alignas(NLMSG_ALIGNTO) nlmsghdr nlh;
};
- static_assert(sizeof(RtnlMessageHeader) == NLMSG_HDRLEN, "");
+ static_assert(sizeof(RtnlMessageHeader) == NLMSG_HDRLEN);
auto hdr = make_shared<RtnlMessageHeader>();
hdr->nlh.nlmsg_len = sizeof(RtnlMessageHeader) + payloadLen;
@@ -472,7 +472,7 @@
alignas(NLMSG_ALIGNTO) nlmsghdr nlh;
alignas(NLMSG_ALIGNTO) genlmsghdr genlh;
};
- static_assert(sizeof(GenlMessageHeader) == NLMSG_SPACE(GENL_HDRLEN), "");
+ static_assert(sizeof(GenlMessageHeader) == NLMSG_SPACE(GENL_HDRLEN));
auto hdr = make_shared<GenlMessageHeader>();
hdr->nlh.nlmsg_len = sizeof(GenlMessageHeader) + payloadLen;
diff --git a/ndn-cxx/prefix-announcement.cpp b/ndn-cxx/prefix-announcement.cpp
index e718fc5..b1870bd 100644
--- a/ndn-cxx/prefix-announcement.cpp
+++ b/ndn-cxx/prefix-announcement.cpp
@@ -24,9 +24,6 @@
namespace ndn {
-static_assert(std::is_convertible_v<PrefixAnnouncement::Error*, tlv::Error*>,
- "PrefixAnnouncement::Error must inherit from tlv::Error");
-
PrefixAnnouncement::PrefixAnnouncement() = default;
PrefixAnnouncement::PrefixAnnouncement(Data data)
@@ -126,14 +123,6 @@
return nc;
}
-bool
-operator==(const PrefixAnnouncement& lhs, const PrefixAnnouncement& rhs)
-{
- return lhs.getAnnouncedName() == rhs.getAnnouncedName() &&
- lhs.getExpiration() == rhs.getExpiration() &&
- lhs.getValidityPeriod() == rhs.getValidityPeriod();
-}
-
std::ostream&
operator<<(std::ostream& os, const PrefixAnnouncement& pa)
{
diff --git a/ndn-cxx/prefix-announcement.hpp b/ndn-cxx/prefix-announcement.hpp
index 11c29bd..e60bdbb 100644
--- a/ndn-cxx/prefix-announcement.hpp
+++ b/ndn-cxx/prefix-announcement.hpp
@@ -33,7 +33,7 @@
*
* \sa https://redmine.named-data.net/projects/nfd/wiki/PrefixAnnouncement
*/
-class PrefixAnnouncement
+class PrefixAnnouncement : private boost::equality_comparable<PrefixAnnouncement>
{
public:
class Error : public tlv::Error
@@ -126,27 +126,32 @@
static const name::Component&
getKeywordComponent();
+private: // non-member operators
+ // NOTE: the following "hidden friend" operators are available via
+ // argument-dependent lookup only and must be defined inline.
+ // boost::equality_comparable provides != operator.
+
+ /**
+ * \brief Test whether two prefix announcements have the same name, expiration period,
+ * and validity period.
+ */
+ friend bool
+ operator==(const PrefixAnnouncement& lhs, const PrefixAnnouncement& rhs)
+ {
+ return lhs.m_announcedName == rhs.m_announcedName &&
+ lhs.m_expiration == rhs.m_expiration &&
+ lhs.m_validity == rhs.m_validity;
+ }
+
private:
- mutable std::optional<Data> m_data;
Name m_announcedName;
time::milliseconds m_expiration = 0_ms;
std::optional<security::ValidityPeriod> m_validity;
+
+ mutable std::optional<Data> m_data;
};
/**
- * \brief Test whether two prefix announcements have the same name, expiration period,
- * and validity period.
- */
-bool
-operator==(const PrefixAnnouncement& lhs, const PrefixAnnouncement& rhs);
-
-inline bool
-operator!=(const PrefixAnnouncement& lhs, const PrefixAnnouncement& rhs)
-{
- return !(lhs == rhs);
-}
-
-/**
* \brief Print prefix announcement to a stream.
*
* The output is for debugging purposes only. The format may change at any time without notice.
diff --git a/ndn-cxx/security/additional-description.hpp b/ndn-cxx/security/additional-description.hpp
index 09fa9c6..a125a78 100644
--- a/ndn-cxx/security/additional-description.hpp
+++ b/ndn-cxx/security/additional-description.hpp
@@ -33,7 +33,7 @@
* @brief Represents an %AdditionalDescription TLV element.
* @sa https://docs.named-data.net/NDN-packet-spec/0.3/certificate.html
*/
-class AdditionalDescription
+class AdditionalDescription : private boost::equality_comparable<AdditionalDescription>
{
public:
class Error : public tlv::Error
@@ -107,9 +107,10 @@
void
wireDecode(const Block& wire);
-private: // EqualityComparable concept
+private: // non-member operators
// NOTE: the following "hidden friend" operators are available via
// argument-dependent lookup only and must be defined inline.
+ // boost::equality_comparable provides != operator.
friend bool
operator==(const AdditionalDescription& lhs, const AdditionalDescription& rhs)
@@ -117,12 +118,6 @@
return lhs.m_info == rhs.m_info;
}
- friend bool
- operator!=(const AdditionalDescription& lhs, const AdditionalDescription& rhs)
- {
- return lhs.m_info != rhs.m_info;
- }
-
private:
std::map<std::string, std::string> m_info;
diff --git a/ndn-cxx/security/key-chain.cpp b/ndn-cxx/security/key-chain.cpp
index 16f6c42..5c23d0d 100644
--- a/ndn-cxx/security/key-chain.cpp
+++ b/ndn-cxx/security/key-chain.cpp
@@ -112,7 +112,7 @@
{
public:
[[nodiscard]] bool
- empty() const
+ empty() const noexcept
{
return scheme.empty();
}
@@ -124,7 +124,7 @@
}
friend bool
- operator==(const Locator& lhs, const Locator& rhs)
+ operator==(const Locator& lhs, const Locator& rhs) noexcept
{
return lhs.scheme == rhs.scheme && lhs.location == rhs.location;
}
diff --git a/ndn-cxx/security/pib/certificate-container.cpp b/ndn-cxx/security/pib/certificate-container.cpp
index 873e37d..1fb630d 100644
--- a/ndn-cxx/security/pib/certificate-container.cpp
+++ b/ndn-cxx/security/pib/certificate-container.cpp
@@ -27,22 +27,8 @@
NDN_LOG_INIT(ndn.security.CertificateContainer);
-CertificateContainer::const_iterator::const_iterator(NameSet::const_iterator it,
- const CertificateContainer& container) noexcept
- : m_it(it)
- , m_container(&container)
-{
-}
-
-Certificate
-CertificateContainer::const_iterator::operator*()
-{
- BOOST_ASSERT(m_container != nullptr);
- return m_container->get(*m_it);
-}
-
bool
-CertificateContainer::const_iterator::operator==(const const_iterator& other) const
+CertificateContainer::const_iterator::equals(const const_iterator& other) const noexcept
{
bool isThisEnd = m_container == nullptr || m_it == m_container->m_certNames.end();
bool isOtherEnd = other.m_container == nullptr || other.m_it == other.m_container->m_certNames.end();
diff --git a/ndn-cxx/security/pib/certificate-container.hpp b/ndn-cxx/security/pib/certificate-container.hpp
index 7c98468..3cd4b94 100644
--- a/ndn-cxx/security/pib/certificate-container.hpp
+++ b/ndn-cxx/security/pib/certificate-container.hpp
@@ -24,7 +24,6 @@
#include "ndn-cxx/security/certificate.hpp"
-#include <iterator>
#include <set>
#include <unordered_map>
@@ -46,19 +45,17 @@
using NameSet = std::set<Name>;
public:
- class const_iterator
+ class const_iterator : public boost::forward_iterator_helper<const_iterator, const Certificate>
{
public:
- using iterator_category = std::forward_iterator_tag;
- using value_type = const Certificate;
- using difference_type = std::ptrdiff_t;
- using pointer = value_type*;
- using reference = value_type&;
-
const_iterator() = default;
Certificate
- operator*();
+ operator*() const
+ {
+ BOOST_ASSERT(m_container != nullptr);
+ return m_container->get(*m_it);
+ }
const_iterator&
operator++()
@@ -67,25 +64,21 @@
return *this;
}
- const_iterator
- operator++(int)
+ friend bool
+ operator==(const const_iterator& lhs, const const_iterator& rhs) noexcept
{
- const_iterator it(*this);
- ++m_it;
- return it;
- }
-
- bool
- operator==(const const_iterator& other) const;
-
- bool
- operator!=(const const_iterator& other) const
- {
- return !this->operator==(other);
+ return lhs.equals(rhs);
}
private:
- const_iterator(NameSet::const_iterator it, const CertificateContainer& container) noexcept;
+ const_iterator(NameSet::const_iterator it, const CertificateContainer& container) noexcept
+ : m_it(it)
+ , m_container(&container)
+ {
+ }
+
+ bool
+ equals(const const_iterator& other) const noexcept;
private:
NameSet::const_iterator m_it;
diff --git a/ndn-cxx/security/pib/identity-container.cpp b/ndn-cxx/security/pib/identity-container.cpp
index 8d80b95..6458885 100644
--- a/ndn-cxx/security/pib/identity-container.cpp
+++ b/ndn-cxx/security/pib/identity-container.cpp
@@ -28,22 +28,8 @@
NDN_LOG_INIT(ndn.security.IdentityContainer);
-IdentityContainer::const_iterator::const_iterator(NameSet::const_iterator it,
- const IdentityContainer& container) noexcept
- : m_it(it)
- , m_container(&container)
-{
-}
-
-Identity
-IdentityContainer::const_iterator::operator*()
-{
- BOOST_ASSERT(m_container != nullptr);
- return m_container->get(*m_it);
-}
-
bool
-IdentityContainer::const_iterator::operator==(const const_iterator& other) const
+IdentityContainer::const_iterator::equals(const const_iterator& other) const noexcept
{
bool isThisEnd = m_container == nullptr || m_it == m_container->m_identityNames.end();
bool isOtherEnd = other.m_container == nullptr || other.m_it == other.m_container->m_identityNames.end();
diff --git a/ndn-cxx/security/pib/identity-container.hpp b/ndn-cxx/security/pib/identity-container.hpp
index 786c7ba..da844b1 100644
--- a/ndn-cxx/security/pib/identity-container.hpp
+++ b/ndn-cxx/security/pib/identity-container.hpp
@@ -24,7 +24,6 @@
#include "ndn-cxx/security/pib/identity.hpp"
-#include <iterator>
#include <set>
#include <unordered_map>
@@ -46,19 +45,17 @@
using NameSet = std::set<Name>;
public:
- class const_iterator
+ class const_iterator : public boost::forward_iterator_helper<const_iterator, const Identity>
{
public:
- using iterator_category = std::forward_iterator_tag;
- using value_type = const Identity;
- using difference_type = std::ptrdiff_t;
- using pointer = value_type*;
- using reference = value_type&;
-
const_iterator() = default;
Identity
- operator*();
+ operator*() const
+ {
+ BOOST_ASSERT(m_container != nullptr);
+ return m_container->get(*m_it);
+ }
const_iterator&
operator++()
@@ -67,25 +64,21 @@
return *this;
}
- const_iterator
- operator++(int)
+ friend bool
+ operator==(const const_iterator& lhs, const const_iterator& rhs) noexcept
{
- const_iterator it(*this);
- ++m_it;
- return it;
- }
-
- bool
- operator==(const const_iterator& other) const;
-
- bool
- operator!=(const const_iterator& other) const
- {
- return !this->operator==(other);
+ return lhs.equals(rhs);
}
private:
- const_iterator(NameSet::const_iterator it, const IdentityContainer& container) noexcept;
+ const_iterator(NameSet::const_iterator it, const IdentityContainer& container) noexcept
+ : m_it(it)
+ , m_container(&container)
+ {
+ }
+
+ bool
+ equals(const const_iterator& other) const noexcept;
private:
NameSet::const_iterator m_it;
diff --git a/ndn-cxx/security/pib/identity.hpp b/ndn-cxx/security/pib/identity.hpp
index b39335b..812bb3c 100644
--- a/ndn-cxx/security/pib/identity.hpp
+++ b/ndn-cxx/security/pib/identity.hpp
@@ -40,7 +40,7 @@
* name, and contains zero or more keys, at most one of which is set as the default key of that
* identity. The properties of a key can be accessed after obtaining a Key object.
*/
-class Identity
+class Identity : private boost::equality_comparable<Identity>
{
public:
/**
@@ -154,19 +154,14 @@
// NOTE
// The following "hidden friend" non-member operators are available
// via argument-dependent lookup only and must be defined inline.
+ // boost::equality_comparable provides != operator.
friend bool
- operator==(const Identity& lhs, const Identity& rhs)
+ operator==(const Identity& lhs, const Identity& rhs) noexcept
{
return lhs.equals(rhs);
}
- friend bool
- operator!=(const Identity& lhs, const Identity& rhs)
- {
- return !lhs.equals(rhs);
- }
-
friend std::ostream&
operator<<(std::ostream& os, const Identity& id)
{
diff --git a/ndn-cxx/security/pib/key-container.cpp b/ndn-cxx/security/pib/key-container.cpp
index 94084ce..12cb64d 100644
--- a/ndn-cxx/security/pib/key-container.cpp
+++ b/ndn-cxx/security/pib/key-container.cpp
@@ -28,22 +28,8 @@
NDN_LOG_INIT(ndn.security.KeyContainer);
-KeyContainer::const_iterator::const_iterator(NameSet::const_iterator it,
- const KeyContainer& container) noexcept
- : m_it(it)
- , m_container(&container)
-{
-}
-
-Key
-KeyContainer::const_iterator::operator*()
-{
- BOOST_ASSERT(m_container != nullptr);
- return m_container->get(*m_it);
-}
-
bool
-KeyContainer::const_iterator::operator==(const const_iterator& other) const
+KeyContainer::const_iterator::equals(const const_iterator& other) const noexcept
{
bool isThisEnd = m_container == nullptr || m_it == m_container->m_keyNames.end();
bool isOtherEnd = other.m_container == nullptr || other.m_it == other.m_container->m_keyNames.end();
diff --git a/ndn-cxx/security/pib/key-container.hpp b/ndn-cxx/security/pib/key-container.hpp
index 2b9b36c..596ba41 100644
--- a/ndn-cxx/security/pib/key-container.hpp
+++ b/ndn-cxx/security/pib/key-container.hpp
@@ -24,7 +24,6 @@
#include "ndn-cxx/security/pib/key.hpp"
-#include <iterator>
#include <set>
#include <unordered_map>
@@ -46,19 +45,17 @@
using NameSet = std::set<Name>;
public:
- class const_iterator
+ class const_iterator : public boost::forward_iterator_helper<const_iterator, const Key>
{
public:
- using iterator_category = std::forward_iterator_tag;
- using value_type = const Key;
- using difference_type = std::ptrdiff_t;
- using pointer = value_type*;
- using reference = value_type&;
-
const_iterator() = default;
Key
- operator*();
+ operator*() const
+ {
+ BOOST_ASSERT(m_container != nullptr);
+ return m_container->get(*m_it);
+ }
const_iterator&
operator++()
@@ -67,25 +64,21 @@
return *this;
}
- const_iterator
- operator++(int)
+ friend bool
+ operator==(const const_iterator& lhs, const const_iterator& rhs) noexcept
{
- const_iterator it(*this);
- ++m_it;
- return it;
- }
-
- bool
- operator==(const const_iterator& other) const;
-
- bool
- operator!=(const const_iterator& other) const
- {
- return !this->operator==(other);
+ return lhs.equals(rhs);
}
private:
- const_iterator(NameSet::const_iterator it, const KeyContainer& container) noexcept;
+ const_iterator(NameSet::const_iterator it, const KeyContainer& container) noexcept
+ : m_it(it)
+ , m_container(&container)
+ {
+ }
+
+ bool
+ equals(const const_iterator& other) const noexcept;
private:
NameSet::const_iterator m_it;
diff --git a/ndn-cxx/security/pib/key.hpp b/ndn-cxx/security/pib/key.hpp
index bd548fa..046aa58 100644
--- a/ndn-cxx/security/pib/key.hpp
+++ b/ndn-cxx/security/pib/key.hpp
@@ -41,7 +41,7 @@
* `/<Identity>/KEY/<KeyId>`, and contains one or more certificates, one of which is set as
* default certificate of that key. Certificates can be directly accessed from a Key object.
*/
-class Key
+class Key : private boost::equality_comparable<Key>
{
public:
/**
@@ -173,19 +173,14 @@
// NOTE
// The following "hidden friend" non-member operators are available
// via argument-dependent lookup only and must be defined inline.
+ // boost::equality_comparable provides != operator.
friend bool
- operator==(const Key& lhs, const Key& rhs)
+ operator==(const Key& lhs, const Key& rhs) noexcept
{
return lhs.equals(rhs);
}
- friend bool
- operator!=(const Key& lhs, const Key& rhs)
- {
- return !lhs.equals(rhs);
- }
-
friend std::ostream&
operator<<(std::ostream& os, const Key& key)
{
diff --git a/ndn-cxx/security/transform/hex-decode.cpp b/ndn-cxx/security/transform/hex-decode.cpp
index 9cbccf7..97e6774 100644
--- a/ndn-cxx/security/transform/hex-decode.cpp
+++ b/ndn-cxx/security/transform/hex-decode.cpp
@@ -43,7 +43,7 @@
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 224-239
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 240-255
};
-static_assert(std::extent_v<decltype(C2H)> == 256, "");
+static_assert(std::extent_v<decltype(C2H)> == 256);
HexDecode::HexDecode()
diff --git a/ndn-cxx/security/transform/hex-encode.cpp b/ndn-cxx/security/transform/hex-encode.cpp
index 0a9da8d..1dc759a 100644
--- a/ndn-cxx/security/transform/hex-encode.cpp
+++ b/ndn-cxx/security/transform/hex-encode.cpp
@@ -27,13 +27,13 @@
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
-static_assert(std::extent_v<decltype(H2CL)> == 16, "");
+static_assert(std::extent_v<decltype(H2CL)> == 16);
static const uint8_t H2CU[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
-static_assert(std::extent_v<decltype(H2CU)> == 16, "");
+static_assert(std::extent_v<decltype(H2CU)> == 16);
HexEncode::HexEncode(bool useUpperCase)
diff --git a/ndn-cxx/security/validity-period.hpp b/ndn-cxx/security/validity-period.hpp
index f4da2f4..a4b204c 100644
--- a/ndn-cxx/security/validity-period.hpp
+++ b/ndn-cxx/security/validity-period.hpp
@@ -32,7 +32,7 @@
* @brief Represents a %ValidityPeriod TLV element.
* @sa https://docs.named-data.net/NDN-packet-spec/0.3/certificate.html
*/
-class ValidityPeriod
+class ValidityPeriod : private boost::equality_comparable<ValidityPeriod>
{
public:
class Error : public tlv::Error
@@ -135,21 +135,16 @@
static TimePoint
decodeTimePoint(const Block& element);
-private: // EqualityComparable concept
+private: // non-member operators
// NOTE: the following "hidden friend" operators are available via
// argument-dependent lookup only and must be defined inline.
+ // boost::equality_comparable provides != operator.
friend bool
operator==(const ValidityPeriod& lhs, const ValidityPeriod& rhs)
{
- return !(lhs != rhs);
- }
-
- friend bool
- operator!=(const ValidityPeriod& lhs, const ValidityPeriod& rhs)
- {
- return lhs.m_notBefore != rhs.m_notBefore ||
- lhs.m_notAfter != rhs.m_notAfter;
+ return lhs.m_notBefore == rhs.m_notBefore &&
+ lhs.m_notAfter == rhs.m_notAfter;
}
private:
diff --git a/ndn-cxx/util/backports.hpp b/ndn-cxx/util/backports.hpp
index d9932f5..18c2c98 100644
--- a/ndn-cxx/util/backports.hpp
+++ b/ndn-cxx/util/backports.hpp
@@ -44,7 +44,7 @@
to_underlying(T val) noexcept
{
// instantiating underlying_type with a non-enum type is UB before C++20
- static_assert(std::is_enum_v<T>, "");
+ static_assert(std::is_enum_v<T>);
return static_cast<std::underlying_type_t<T>>(val);
}
#endif // __cpp_lib_to_underlying
diff --git a/ndn-cxx/util/concepts.hpp b/ndn-cxx/util/concepts.hpp
index bcd336d..7cd71f6 100644
--- a/ndn-cxx/util/concepts.hpp
+++ b/ndn-cxx/util/concepts.hpp
@@ -99,10 +99,10 @@
public:
BOOST_CONCEPT_USAGE(NfdMgmtProtocolStruct)
{
- static_assert(std::is_default_constructible_v<X>, "");
- static_assert(boost::has_equal_to<X, X, bool>::value, "");
- static_assert(boost::has_not_equal_to<X, X, bool>::value, "");
- static_assert(boost::has_left_shift<std::ostream, X, std::ostream&>::value, "");
+ static_assert(std::is_default_constructible_v<X>);
+ static_assert(boost::has_equal_to<X, X, bool>::value);
+ static_assert(boost::has_not_equal_to<X, X, bool>::value);
+ static_assert(boost::has_left_shift<std::ostream, X, std::ostream&>::value);
static_assert(std::is_convertible_v<typename X::Error*, tlv::Error*>,
"ndn::tlv::Error must be a public base of X::Error");
}
diff --git a/ndn-cxx/util/scheduler.cpp b/ndn-cxx/util/scheduler.cpp
index ecc9c7f..fae2a84 100644
--- a/ndn-cxx/util/scheduler.cpp
+++ b/ndn-cxx/util/scheduler.cpp
@@ -67,12 +67,6 @@
*this = {};
}
-std::ostream&
-operator<<(std::ostream& os, const EventId& eventId)
-{
- return os << eventId.m_info.lock();
-}
-
bool
Scheduler::EventQueueCompare::operator()(const shared_ptr<EventInfo>& a,
const shared_ptr<EventInfo>& b) const noexcept
diff --git a/ndn-cxx/util/scheduler.hpp b/ndn-cxx/util/scheduler.hpp
index b5dd908..e82b151 100644
--- a/ndn-cxx/util/scheduler.hpp
+++ b/ndn-cxx/util/scheduler.hpp
@@ -26,7 +26,9 @@
#include "ndn-cxx/detail/cancel-handle.hpp"
#include "ndn-cxx/util/time.hpp"
+#include <boost/operators.hpp>
#include <boost/system/error_code.hpp>
+
#include <set>
namespace ndn {
@@ -55,32 +57,40 @@
* \warning Canceling an event after the scheduler has been destructed may trigger undefined
* behavior.
*/
-class EventId : public detail::CancelHandle
+class EventId : public detail::CancelHandle, private boost::equality_comparable<EventId>
{
public:
- /** \brief Constructs an empty EventId
+ /**
+ * \brief Constructs an empty EventId.
*/
EventId() noexcept = default;
- /** \brief Determine whether the event is valid.
- * \retval true The event is valid.
- * \retval false This EventId is empty, or the event is expired or cancelled.
+ /**
+ * \brief Determine whether the associated event is valid.
+ * \retval true The event is valid.
+ * \retval false This EventId is empty, or the event is expired or cancelled.
*/
explicit
operator bool() const noexcept;
- /** \brief Clear this EventId without canceling.
- * \post !(*this)
+ /**
+ * \brief Clear this EventId without canceling the associated event.
+ * \post !(*this)
*/
void
reset() noexcept;
private:
+ EventId(Scheduler& sched, weak_ptr<EventInfo> info);
+
+private: // non-member operators
// NOTE: the following "hidden friend" operators are available via
// argument-dependent lookup only and must be defined inline.
+ // boost::equality_comparable provides != operator.
- /** \brief Determine whether this and other refer to the same event, or are both
- * empty/expired/cancelled.
+ /**
+ * \brief Determine whether \p lhs and \p rhs refer to the same event, or are both
+ * empty/expired/cancelled.
*/
friend bool
operator==(const EventId& lhs, const EventId& rhs) noexcept
@@ -90,25 +100,18 @@
!rhs.m_info.owner_before(lhs.m_info));
}
- friend bool
- operator!=(const EventId& lhs, const EventId& rhs) noexcept
+ friend std::ostream&
+ operator<<(std::ostream& os, const EventId& eventId)
{
- return !(lhs == rhs);
+ return os << eventId.m_info.lock();
}
private:
- EventId(Scheduler& sched, weak_ptr<EventInfo> info);
-
-private:
weak_ptr<EventInfo> m_info;
friend Scheduler;
- friend std::ostream& operator<<(std::ostream& os, const EventId& eventId);
};
-std::ostream&
-operator<<(std::ostream& os, const EventId& eventId);
-
/** \brief A scoped handle for a scheduled event.
*
* Upon destruction of this handle, the event is canceled automatically.
diff --git a/ndn-cxx/util/signal/connection.hpp b/ndn-cxx/util/signal/connection.hpp
index 477d22c..d27dcb2 100644
--- a/ndn-cxx/util/signal/connection.hpp
+++ b/ndn-cxx/util/signal/connection.hpp
@@ -24,6 +24,8 @@
#include "ndn-cxx/detail/common.hpp"
+#include <boost/operators.hpp>
+
namespace ndn::signal {
using DisconnectFunction = std::function<void()>;
@@ -32,22 +34,24 @@
* \brief Represents a connection to a signal.
* \note This type is copyable. Any copy can be used to disconnect.
*/
-class Connection
+class Connection : private boost::equality_comparable<Connection>
{
public:
constexpr
Connection() noexcept = default;
- /** \brief Disconnects from the signal.
- * \note If the connection is already disconnected, or if the Signal has been destructed,
- * this operation has no effect.
- * \warning During signal emission, attempting to disconnect a connection other than
- * the executing handler's own connection results in undefined behavior.
+ /**
+ * \brief Disconnects from the signal.
+ * \note If the connection is already disconnected, or if the Signal has been destructed,
+ * this operation has no effect.
+ * \warning During signal emission, attempting to disconnect a connection other than
+ * the executing handler's own connection results in undefined behavior.
*/
void
disconnect();
- /** \brief Check if connected to the signal.
+ /**
+ * \brief Check if connected to the signal.
*/
bool
isConnected() const noexcept
@@ -56,22 +60,22 @@
}
private:
- /** \param disconnect weak_ptr to a function that disconnects the handler
- */
explicit
Connection(weak_ptr<DisconnectFunction> disconnect) noexcept;
template<typename Owner, typename... TArgs>
friend class Signal;
-private:
+private: // non-member operators
// NOTE: the following "hidden friend" operators are available via
// argument-dependent lookup only and must be defined inline.
+ // boost::equality_comparable provides != operator.
- /** \brief Compare for equality.
+ /**
+ * \brief Compare for equality.
*
- * Two connections are equal if they both refer to the same connection that isn't disconnected,
- * or they are both disconnected.
+ * Two connections are equal if they both refer to the same connection that isn't disconnected,
+ * or they are both disconnected.
*/
friend bool
operator==(const Connection& lhs, const Connection& rhs) noexcept
@@ -81,12 +85,6 @@
!rhs.m_disconnect.owner_before(lhs.m_disconnect));
}
- friend bool
- operator!=(const Connection& lhs, const Connection& rhs) noexcept
- {
- return !(lhs == rhs);
- }
-
private:
/** \note The only shared_ptr to the disconnect function is stored in Signal<..>::Slot,
* and will be destructed if the handler is disconnected (through another Connection
diff --git a/tests/benchmarks/encoding-bench.cpp b/tests/benchmarks/encoding-bench.cpp
index a3e0b5e..7694d89 100644
--- a/tests/benchmarks/encoding-bench.cpp
+++ b/tests/benchmarks/encoding-bench.cpp
@@ -68,7 +68,7 @@
{
using AlignmentOffset = std::integral_constant<size_t, ALIGNMENT_OFFSET>;
- static_assert(sizeof(ReadVarNumberTest<WIRE_SIZE>::WIRE) == WIRE_SIZE, "");
+ static_assert(sizeof(ReadVarNumberTest<WIRE_SIZE>::WIRE) == WIRE_SIZE);
};
using ReadVarNumberTests = boost::mpl::vector<
@@ -97,7 +97,7 @@
constexpr int N_ITERATIONS = 100000000;
alignas(8) uint8_t buffer[16];
- static_assert(Test::AlignmentOffset::value + sizeof(Test::WIRE) <= sizeof(buffer), "");
+ static_assert(Test::AlignmentOffset::value + sizeof(Test::WIRE) <= sizeof(buffer));
uint8_t* const begin = buffer + Test::AlignmentOffset::value;
std::memcpy(begin, Test::WIRE, sizeof(Test::WIRE));
const uint8_t* const end = begin + sizeof(Test::WIRE);
diff --git a/tests/unit/face.t.cpp b/tests/unit/face.t.cpp
index c4ae026..f369d6f 100644
--- a/tests/unit/face.t.cpp
+++ b/tests/unit/face.t.cpp
@@ -44,7 +44,7 @@
: face(m_io, m_keyChain, {true, !std::is_same_v<PrefixRegReply, NoPrefixRegReply>})
{
static_assert(std::is_same_v<PrefixRegReply, WantPrefixRegReply> ||
- std::is_same_v<PrefixRegReply, NoPrefixRegReply>, "");
+ std::is_same_v<PrefixRegReply, NoPrefixRegReply>);
}
/** \brief Execute a prefix registration, and optionally check the name in callback.
diff --git a/tests/unit/interest.t.cpp b/tests/unit/interest.t.cpp
index bd6e302..73b7bef 100644
--- a/tests/unit/interest.t.cpp
+++ b/tests/unit/interest.t.cpp
@@ -31,6 +31,7 @@
BOOST_CONCEPT_ASSERT((WireDecodable<Interest>));
static_assert(std::is_convertible_v<Interest::Error*, tlv::Error*>,
"Interest::Error must inherit from tlv::Error");
+BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Interest::Nonce>));
BOOST_AUTO_TEST_SUITE(TestInterest)
diff --git a/tests/unit/metadata-object.t.cpp b/tests/unit/metadata-object.t.cpp
index 480f7d4..0cbe737 100644
--- a/tests/unit/metadata-object.t.cpp
+++ b/tests/unit/metadata-object.t.cpp
@@ -26,6 +26,9 @@
namespace ndn::tests {
+static_assert(std::is_convertible_v<MetadataObject::Error*, tlv::Error*>,
+ "MetadataObject::Error must inherit from tlv::Error");
+
class MetadataObjectFixture : public KeyChainFixture
{
public:
diff --git a/tests/unit/name-component.t.cpp b/tests/unit/name-component.t.cpp
index d72de0f..d4b674d 100644
--- a/tests/unit/name-component.t.cpp
+++ b/tests/unit/name-component.t.cpp
@@ -35,7 +35,9 @@
using ndn::name::Component;
using ndn::name::UriFormat;
+static_assert(sizeof(Component) == sizeof(Block));
BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Component>));
+BOOST_CONCEPT_ASSERT((boost::Comparable<Component>));
BOOST_CONCEPT_ASSERT((WireEncodable<Component>));
BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<Component>));
BOOST_CONCEPT_ASSERT((WireDecodable<Component>));
diff --git a/tests/unit/name.t.cpp b/tests/unit/name.t.cpp
index da95aed..734edb7 100644
--- a/tests/unit/name.t.cpp
+++ b/tests/unit/name.t.cpp
@@ -31,6 +31,7 @@
using ndn::name::Component;
BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Name>));
+BOOST_CONCEPT_ASSERT((boost::Comparable<Name>));
BOOST_CONCEPT_ASSERT((WireEncodable<Name>));
BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<Name>));
BOOST_CONCEPT_ASSERT((WireDecodable<Name>));
diff --git a/tests/unit/prefix-announcement.t.cpp b/tests/unit/prefix-announcement.t.cpp
index a13e9f5..a36f084 100644
--- a/tests/unit/prefix-announcement.t.cpp
+++ b/tests/unit/prefix-announcement.t.cpp
@@ -27,6 +27,10 @@
namespace ndn::tests {
+BOOST_CONCEPT_ASSERT((boost::EqualityComparable<PrefixAnnouncement>));
+static_assert(std::is_convertible_v<PrefixAnnouncement::Error*, tlv::Error*>,
+ "PrefixAnnouncement::Error must inherit from tlv::Error");
+
BOOST_AUTO_TEST_SUITE(TestPrefixAnnouncement)
static Data
diff --git a/tests/unit/security/pib/identity.t.cpp b/tests/unit/security/pib/identity.t.cpp
index 70252d9..42a9916 100644
--- a/tests/unit/security/pib/identity.t.cpp
+++ b/tests/unit/security/pib/identity.t.cpp
@@ -29,6 +29,8 @@
using namespace ndn::security::pib;
+BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Identity>));
+
BOOST_AUTO_TEST_SUITE(Security)
BOOST_FIXTURE_TEST_SUITE(TestIdentity, PibDataFixture)
diff --git a/tests/unit/security/pib/key.t.cpp b/tests/unit/security/pib/key.t.cpp
index 5273436..a3c1806 100644
--- a/tests/unit/security/pib/key.t.cpp
+++ b/tests/unit/security/pib/key.t.cpp
@@ -29,6 +29,8 @@
using namespace ndn::security::pib;
+BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Key>));
+
BOOST_AUTO_TEST_SUITE(Security)
BOOST_FIXTURE_TEST_SUITE(TestKey, PibDataFixture)
diff --git a/tests/unit/util/ostream-joiner.t.cpp b/tests/unit/util/ostream-joiner.t.cpp
index 2e7ac8f..4ac3381 100644
--- a/tests/unit/util/ostream-joiner.t.cpp
+++ b/tests/unit/util/ostream-joiner.t.cpp
@@ -37,7 +37,7 @@
auto joiner1 = ostream_joiner<char>(os, ' ');
auto joiner2 = make_ostream_joiner(os, ' ');
- static_assert(std::is_same_v<decltype(joiner1), decltype(joiner2)>, "");
+ static_assert(std::is_same_v<decltype(joiner1), decltype(joiner2)>);
std::vector<int> v(5);
std::iota(v.begin(), v.end(), 1);
diff --git a/tests/unit/version.t.cpp b/tests/unit/version.t.cpp
index 527bc95..4b551a9 100644
--- a/tests/unit/version.t.cpp
+++ b/tests/unit/version.t.cpp
@@ -37,9 +37,9 @@
NDN_CXX_VERSION_MINOR * 1000 +
NDN_CXX_VERSION_PATCH);
- static_assert(NDN_CXX_VERSION_MAJOR < 1000, "");
- static_assert(NDN_CXX_VERSION_MINOR < 1000, "");
- static_assert(NDN_CXX_VERSION_PATCH < 1000, "");
+ static_assert(NDN_CXX_VERSION_MAJOR < 1000);
+ static_assert(NDN_CXX_VERSION_MINOR < 1000);
+ static_assert(NDN_CXX_VERSION_PATCH < 1000);
}
BOOST_AUTO_TEST_CASE(VersionString)