I will have to say that it is irreproducible.
I used my version of Visual Studio 2015 Update 3, and the output is normal:
66 79 154 24 76 13 7
In addition, when implementing VC ++, there are no problems with moving the vector to itself:
_Myt& operator=(_Myt&& _Right) { // assign by moving _Right if (this != &_Right) { // different, assign it clear(); if (_Alty::propagate_on_container_move_assignment::value && this->get_allocator() != _Right.get_allocator()) { // assign vector, dumping proxy this->_Free_proxy(); this->_Myvec = _STD move(_Right._Myvec); this->_Alloc_proxy(); } else this->_Myvec = _STD move(_Right._Myvec); this->_Mysize = _Right._Mysize; _Right._Mysize = 0; } return (*this); }
as you can see from the condition this != &_Right
, the movement will happen only if you do not move the vector toward you.
EDIT:
Apparently, the compiler that is used to compile “C ++ 14” to Ideone (GCC?) Decides not to check the self-translation of the destination and decides to free the vector data. as we can see from this small experiment , after moving the size of the vector is 0. as stated in other previous answers / comments, assigning a move for itself implements the implementation. I think VC ++ is doing the right thing in this case.
EDIT 2:
it seems that GCC does not really check self-esteem. it moves vector data to temporary and accepts __x
data that is already empty at that point. man, sometimes GCC behaves stupidly for radial performance (because cmp + jz will really slow down your program?)
source share