
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Monday 24 August 2009, Ion Gaztañaga wrote:
Thomas Klimpel escribió:
I would say that if an automatic "bad smell" detection tool like Coverity would flag the above code as dangerous, it wouldn't be completely wrong. After mx was used via boost::move(mx), it is not supposed to be used again. So I think it would be better to write
vector(BOOST_RV_REF(vector) mx) : base_t(mx) { this->swap(mx); }
which is also less confusing for a human reader.
Yes, but that wouldn't be the right thing. When writing move constructors one must first move base classes and then members.
Yes, but the swap swaps both the base members and derived members.
Otherwise, the base it's copied instead of moved. Anyway, I think this should be reflected better casting mx to base_t and then moved.
Wouldn't it look less suspicious if base_t were constructed the same way as in the default vector constructor? In this case moving into the base class can't accomplish anything useful even in principle, since whatever it does will be blown away by the swap. And if a move constructor were added to base_t (detail::vector_alloc_holder doesn't appear to have one) which modified its moved-from argument, it wouldn't cause bugs. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkqSn/QACgkQ5vihyNWuA4VOXwCdEt/03LF7JmtHH8CQu4VBOFsl 0R8AnRCooy6YsQJogwaa2I6NRL3WI+eX =3nqR -----END PGP SIGNATURE-----