[zeromq-dev] C++ Move Constructor and Assignment Operator

Christoph Heindl christoph.heindl at gmail.com
Thu Feb 14 08:38:40 CET 2013


I was using the Cpp ZMQ interface lately and while writing a bunch of unit
tests I came accross curious behaviour in the move constructor and
assignment operator of zmq::message_t.

The following tests fail (zmq 3.2.2, latest zmq.hpp from github, MSVC10)

      zmq::message_t m0(10);
      void *adr = m0.data();

      zmq::message_t m1;
      m1 = std::move(m0);

      BOOST_REQUIRE_EQUAL(adr, m1.data());

It might be a semantic error on my side, but I would have thought that an
efficient implementation would happly reuse the buffer allocated by m0.
Instead i get a different buffer address. Similarily the move constructor
seems to re(a)locate the buffer

      zmq::message_t m0(10);
      void *adr = m0.data();

      zmq::message_t m1(std::move(m0));

      BOOST_REQUIRE_EQUAL(adr, m1.data())

Is this behaviour intended?

Btw. in zmq.hpp std::swap is used in the move assignment operator. This
seems to me as both buffers survive (at least temporarily) in a scenario as
described above ( zmq::message_t m1(std::move(m0))). I guess that has
something todo with the fact that closing the message is always done in the

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130214/9368ba88/attachment.html>

More information about the zeromq-dev mailing list