openMSX
utils
ScopedAssign.hh
Go to the documentation of this file.
1
#ifndef SCOPEDASSIGN_HH
2
#define SCOPEDASSIGN_HH
3
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
ScopedAssign
Assign new value to some variable and restore the original value when this object goes out of scope.
Definition:
ScopedAssign.hh:8
ScopedAssign::~ScopedAssign
~ScopedAssign()
Definition:
ScopedAssign.hh:16
ScopedAssign::ScopedAssign
ScopedAssign(T &var_, T newValue)
Definition:
ScopedAssign.hh:10
Generated on Mon Sep 18 2023 23:13:11 for openMSX by
1.9.4