I have a receiver thread. I want to move the messages into a queue for background processors threads. To put it simply:
std::queue<zmq::message_t> qu;
zmq::message_t msg;
zmq::recv_result_t res = sock.recv(msg, zmq::recv_flags::none);
qu.push(std::move(message));
I get an error:
include/zmq.hpp:745:5: note: declared here
745 | message_t(const message_t &) ZMQ_DELETED_FUNCTION;
Even without std::move
, it's still not working.
I understand that zmq::message_t
are not supposed to be moved like that. What is the correct way of doing that (efficiently, without un needed copying)?
I would expect that message_t
will hold the message data allocated on the heap, and that will be freed in the destructor of the message_t
. In that case, I don't understand what is the issue here.
You could use
qu.emplace(std::move(message))
instead, or explicitly call move()
:
qu.push(message_t{});
message.move(qu.back());