Skip to content

Instantly share code, notes, and snippets.

@mgrabovsky
mgrabovsky / gist:1808014
Last active July 30, 2016 12:25
Scoped temporary variable in C++
// http://stackoverflow.com/a/2553109/227159
/**
* In its constructor temp_value stores a reference to a variable and a copy of the
* variable's original value. In its destructor it restores the referenced variable
* to its original value. So, no matter what you did to the variable between
* construction and destruction, it will be reset when the temp_value object goes out
* of scope.
*/