mirror of
https://github.com/zeromq/cppzmq.git
synced 2025-10-16 18:56:56 +02:00
Problem: message_t should be easier to construct
* Added overload constructor (c++11 only) taking iteratable object. It would be easier to use std::string, std::array etc to construct a message now. Making it a draft for now in case it is too greedy and needs to be more specialize. * Added equal and not euqal operator to message_t as a recommended and expected way of comparing objects in C++. * deprecated C style equal method as operator== should be used instead (point above). * Added message_t test covering all available message_t's constructors
This commit is contained in:
25
zmq.hpp
25
zmq.hpp
@@ -271,6 +271,12 @@ namespace zmq
|
||||
throw error_t ();
|
||||
}
|
||||
|
||||
#if defined(ZMQ_BUILD_DRAFT_API) && defined(ZMQ_CPP11)
|
||||
template<typename T> message_t (const T &msg_)
|
||||
: message_t (std::begin (msg_), std::end (msg_))
|
||||
{}
|
||||
#endif
|
||||
|
||||
#ifdef ZMQ_HAS_RVALUE_REFS
|
||||
inline message_t (message_t &&rhs): msg (rhs.msg)
|
||||
{
|
||||
@@ -379,15 +385,30 @@ namespace zmq
|
||||
return static_cast<T const*>( data() );
|
||||
}
|
||||
|
||||
ZMQ_DEPRECATED("from 4.3.0, use operator== instead")
|
||||
inline bool equal(const message_t* other) const ZMQ_NOTHROW
|
||||
{
|
||||
if (size() != other->size())
|
||||
return false;
|
||||
std::string a(data<char>(), size());
|
||||
std::string b(other->data<char>(), other->size());
|
||||
const std::string a(data<char>(), size());
|
||||
const std::string b(other->data<char>(), other->size());
|
||||
return a == b;
|
||||
}
|
||||
|
||||
inline bool operator==(const message_t &other) const ZMQ_NOTHROW
|
||||
{
|
||||
if (size () != other.size ())
|
||||
return false;
|
||||
const std::string a(data<char>(), size());
|
||||
const std::string b(other.data<char>(), other.size());
|
||||
return a == b;
|
||||
}
|
||||
|
||||
inline bool operator!=(const message_t &other) const ZMQ_NOTHROW
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 1, 0)
|
||||
inline const char* gets(const char *property_)
|
||||
{
|
||||
|
Reference in New Issue
Block a user