mmp / pbrt-v3

Source code for pbrt, the renderer described in the third edition of "Physically Based Rendering: From Theory To Implementation", by Matt Pharr, Wenzel Jakob, and Greg Humphreys.
http://pbrt.org
BSD 2-Clause "Simplified" License
4.87k stars 1.18k forks source link

ScopedAssignment: move assignment operator #207

Closed chaosink closed 5 years ago

chaosink commented 5 years ago

Recover the backup of the old instance before monitoring the new instance.

mmp commented 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.

chaosink commented 5 years ago

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.