by codedokode · 3y ago · 0 comments
> C++ doesn't have rule 4, in C++ the compiler lets us accidentally use the variable after we move out of it.
Why is it so? Moving is not a legacy operation, why did they allow to use moved-out variable?
So moving from a std::string variable means it's still a valid object, only its internal state is now owned by someone else, and the std::string is required to now be in an "empty" (but still valid) state. Most of the "moving" is actually handled by extra code in std::string rather than the core language having rules for how the underlying bytes are moved around, because the core language wasn't changed that much.