Operations on Moved-From Objects
Despite the common misconception that moved-from objects can only be destroyed, the C standard specifies that moved-from objects of standard library types are placed in an unspecified state, allowing for a limited scope of operations. This state arises after an object is moved from, enabling operations that typically do not have preconditions.
Unconditional Operations
The following operations can generally be applied to moved-from objects without encountering preconditions:
Conditional Operations
In contrast, the following operations may require the object not to be in an unspecified state and hence are generally not permissible on moved-from objects:
Regarding std::swap
In the example swap function template, the assignment operations (lines 2 and 3) are valid even though they involve moved-from objects because assignment generally does not have preconditions.
Finally
The standard detailing unspecified-state objects for standard library types is located at 17.6.5.15 [lib.types.movedfrom].
The above is the detailed content of What Operations Are Permissible on Moved-From Standard Library Objects in C ?. For more information, please follow other related articles on the PHP Chinese website!