
Ilya Bobir a écrit :
Thomas Klimpel wrote:
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.
If base(const base_t & rhs) copies rhs into this and if swap(...) swaps everything (including base_t part of a verctor) then the base_t part of mx will be first copied into this and then swaped back into mx.
I do not think this can cause errors unless there is something special about slicing a vector instance, but the copy seems to be redundant.
This depends on what operations moved-from objects support.