mirror of
https://github.com/zeromq/cppzmq.git
synced 2025-04-22 00:30:14 +02:00
Merge pull request #513 from geirhei/geirhei/multipart-equality-operator
Add == and != operators for multipart_t
This commit is contained in:
commit
e0314c959e
@ -75,6 +75,21 @@ TEST_CASE("multipart legacy test", "[multipart]")
|
|||||||
assert(ok);
|
assert(ok);
|
||||||
assert(copy.equal(&multipart));
|
assert(copy.equal(&multipart));
|
||||||
|
|
||||||
|
// Test equality operators
|
||||||
|
assert(copy == multipart);
|
||||||
|
assert(multipart == copy);
|
||||||
|
|
||||||
|
multipart.pop();
|
||||||
|
|
||||||
|
assert(copy != multipart);
|
||||||
|
assert(multipart != copy);
|
||||||
|
|
||||||
|
multipart_t emptyMessage1 {};
|
||||||
|
multipart_t emptyMessage2 {};
|
||||||
|
|
||||||
|
assert(emptyMessage1 == emptyMessage2);
|
||||||
|
assert(emptyMessage2 == emptyMessage1);
|
||||||
|
|
||||||
multipart.clear();
|
multipart.clear();
|
||||||
assert(multipart.empty());
|
assert(multipart.empty());
|
||||||
|
|
||||||
|
@ -612,16 +612,26 @@ class multipart_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if equal to other multipart
|
// Check if equal to other multipart
|
||||||
bool equal(const multipart_t *other) const
|
bool equal(const multipart_t *other) const ZMQ_NOTHROW
|
||||||
{
|
{
|
||||||
if (size() != other->size())
|
return *this == *other;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const multipart_t &other) const ZMQ_NOTHROW
|
||||||
|
{
|
||||||
|
if (size() != other.size())
|
||||||
return false;
|
return false;
|
||||||
for (size_t i = 0; i < size(); i++)
|
for (size_t i = 0; i < size(); i++)
|
||||||
if (*peek(i) != *other->peek(i))
|
if (at(i) != other.at(i))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator!=(const multipart_t &other) const ZMQ_NOTHROW
|
||||||
|
{
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef ZMQ_CPP11
|
#ifdef ZMQ_CPP11
|
||||||
|
|
||||||
// Return single part message_t encoded from this multipart_t.
|
// Return single part message_t encoded from this multipart_t.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user