3 ms·
> (or better named: deep- and flat-copy) That's worse naming, not better! In particular, a copy does not change the thing it copies - but a C++ move does chan
by TomSwirly 4y ago
> (or better named: deep- and flat-copy)
That's worse naming, not better!
In particular, a copy does not change the thing it copies - but a C++ move does change the thing it moves from.
- flohofwoe 4y agoOk "flat-copy-with-src-invalidation". Somehow "move" makes it sound more efficient than copying a C struct, but it's actually the same thing (for POD structs), for non-POD it's even slightly more expensive because you need to fix up the source.
- maccard 4y agoI'm definitely not helping this conversation but: > "flat-copy-with-src-invalidation". That's not what a move is in C++, at all. I wish we got destructive moves in C++, but we didn't (and I understand why..) > for non-POD it's even slightly more expensive because you need to fix up the source. This is just false.
- flohofwoe 4y agoHuh, you really need to elaborate on both points. As far as I remember from my 'active' C++ time, a move operator does a 'flat copy' of all 'top level items' in an object, and then puts the source object into a state where the destructor can safely be called on it without destroying any of the previously owned resources (which means for instance setting any owning pointers to zero so that the destructor doesn't free the memory that was owned by those pointers, because ownership of this memory has moved to the destination object). It gets a bit more non-obvious if any of those items are complex C++ objects themselves, but in the end it's always "copy all the bits, and then clear any owning pointers without freeing the underlying memory". Did I miss something?