Skip to content

Instantly share code, notes, and snippets.

@mrdomino
Last active August 29, 2015 14:14
Show Gist options
  • Save mrdomino/619a67688b6a8d3aa57c to your computer and use it in GitHub Desktop.
Save mrdomino/619a67688b6a8d3aa57c to your computer and use it in GitHub Desktop.
#include <utility>
template <typename T, typename U = T>
class ScopedRestore {
public:
explicit ScopedRestore(T* it):
ref_(*it), old_val_(*it) {}
~ScopedRestore() noexcept(noexcept(this->ref_ = std::move(this->old_val_))) {
using std::move;
ref_ = move(old_val_);
}
private:
T& ref_;
U old_val_;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment