For discussion purposes, I assume that you mean the transition to the fact that the original object was "discarded" (no longer used, did not execute its destructor), and did not have two copies (which would lead to a much bigger problem, reference counting, and etc.). I usually refer to the property of being able to do this bitwise.
In the basics of the code I'm working on, most objects are bit-wise movable, since they do not store independent links. However, some data structures are not bitwise (I believe gcc std :: set was not bitwise, other examples would be linked list nodes ). In general, I would avoid trying to use this property, since this can lead to very difficult debugging of errors and prefer object-oriented calls to copy constructors.
Edited to add :
There seems to be some confusion about how / why someone did this: here is a comment I made about how:
Usually, I see the above implementations of the vector. Memory is allocated through malloc (sizeof (Class) * size) and objects are built in place through explicitly called constructors and destructors. Sometimes (for example, during redistribution), they must be moved, so the std :: vector option re-calls copy constructors to new memory and destructors to old ones, or use memcopy and just “free” the old block. In most cases, the latter simply “works,” but not for all objects.
In this regard, the memcopy (or realloc ) approach can be significantly faster.
Yes, it causes undefined behavior, but it also just works for most objects. Some people think speed is worth it. If you were really configured to use this approach, I would suggest implementing a bitwise_movable property of the type to allow types that work for the white list and return to the traditional copy for objects that are not in the white list, similar to the example here .
source share