Problem: message_t lacks empty() function

Solution: Add function and qualify with nodiscard like std types
This commit is contained in:
Gudmundur Adalsteinsson 2019-04-04 17:55:27 +00:00
parent 5c95a07d72
commit 16f16eeaad
2 changed files with 8 additions and 0 deletions

View File

@ -17,6 +17,7 @@ TEST_CASE("message default constructed", "[message]")
{
const zmq::message_t message;
CHECK(0u == message.size());
CHECK(message.empty());
}
#ifdef ZMQ_CPP11
@ -89,8 +90,10 @@ TEST_CASE("message assign move empty before", "[message]")
TEST_CASE("message assign move empty after", "[message]")
{
zmq::message_t hi_msg(data, strlen(data));
CHECK(!hi_msg.empty());
hi_msg = zmq::message_t();
CHECK(0u == hi_msg.size());
CHECK(hi_msg.empty());
}
TEST_CASE("message assign move empty before and after", "[message]")

View File

@ -396,6 +396,11 @@ class message_t
return zmq_msg_size(const_cast<zmq_msg_t *>(&msg));
}
ZMQ_NODISCARD bool empty() const ZMQ_NOTHROW
{
return size() == 0u;
}
template<typename T> T *data() ZMQ_NOTHROW { return static_cast<T *>(data()); }
template<typename T> T const *data() const ZMQ_NOTHROW