Am I correct thinking that str1 is in valid state now and is totally safe to use after assigning new value to it?
You're correct.
Is it safe to assign new value to an object that has been moved from and use this object further?
They depends on how the move operator/ constructor and the assignment operator have been defined. It can be safe (and usually is) but it can be unsafe (at least in theory).
For all standard library types (that are movable and assignable in the first place) including std::string
, the move operation leaves the moved object in a valid but unspecified state and the assignment operator has no preconditions on the assigned object, so it's always allowed.
It's a good convention to provide similar guarantees for any class, but it's also possible to not do so, in which case it could be unsafe to do such assignment.
string
's assignment operator has preconditions (it doesn't), but the dupe I used doesn't cover that. Sorry about that. – Highline