|
|
|
|
|
by jandrewrogers
391 days ago
|
|
The standard idiom is to have a sentinel state for the object indicating it is invalid. For objects without trivial destructors or which may be read after being moved-from (a valid behavior in some systems code contexts) then you need a sentinel state anyway because moves in C++ are non-destructive. C++ uses deferred destruction as a standard tool to solve a variety of problems. |
|
std::move as applied to standard library types will leave the object in a "valid but unspecified state".[1] If you're leaving the object in an invalid state (one where the invariants are broken), you're not writing idiomatic C++.
[1] https://en.cppreference.com/w/cpp/utility/move.html