Closed chaosink closed 5 years ago
Thanks. Out of curiosity, did you see buggy behavior without this, or did you just happen to notice it.
I suppose another option would be to just std::swap()
the two members and let the destructor for the returned reference take care of this.
Haven't seen buggy behaviors.
I think std::swap()
is not feasible.
For the current implementation, the old instance is recovered in the move assignment oeprator. So users can use the original value of the old instance immediately after move assignment. And the moved-from ScopedAssignment object has no effect any more. This is consistent with the move semantics.
However, with std::swap()
the recovery of the old instance is in the charge of the moved-from ScopedAssignment object.
Recover the backup of the old instance before monitoring the new instance.