openMSX
ScopedAssign.hh
Go to the documentation of this file.
1#ifndef SCOPEDASSIGN_HH
2#define SCOPEDASSIGN_HH
3
7template<typename T> class ScopedAssign
8{
9public:
10 [[nodiscard]] ScopedAssign(T& var_, T newValue)
11 : var(var_)
12 {
13 oldValue = var;
14 var = newValue;
15 }
17 {
18 var = oldValue;
19 }
20private:
21 T& var;
22 T oldValue;
23};
24
25#endif
Assign new value to some variable and restore the original value when this object goes out of scope.
ScopedAssign(T &var_, T newValue)