Debian Codegraph @

src/ScopedAssign.h

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