Scoped temporary variable template. More...
#include <ScopedTemporaryValue.h>
Public Member Functions | |
| ScopedTemporaryValue (T &var) | |
| Constructor, which reads the old value from T, but does not change it. More... | |
| ScopedTemporaryValue (T &var, T newValue) | |
| Constructor, which reads the old value from T, and sets it to a new (temporary) value. More... | |
| ~ScopedTemporaryValue () | |
| Destructor, which restores the original value. More... | |
Scoped temporary variable template.
Usage:
SomeType var = A;
{
ScopedTemporaryValue<SomeType> holder(var);
var = B;
...
}
// var will here be reset to A.
or
SomeType var = A;
{
ScopedTemporaryValue<SomeType> holder(var, B);
// Here, var is B.
...
}
// var will here be reset to A.
Implementation note: This is just a schoolbook-style implementation of a class which holds a variable, and then restores the original value when going out of scope.
Definition at line 59 of file ScopedTemporaryValue.h.
|
inline |
Constructor, which reads the old value from T, but does not change it.
| var | The variable. |
Definition at line 72 of file ScopedTemporaryValue.h.
|
inline |
Constructor, which reads the old value from T, and sets it to a new (temporary) value.
| var | The variable. |
| newValue | The new (temporary) value. |
Definition at line 85 of file ScopedTemporaryValue.h.
|
inline |
Destructor, which restores the original value.
Definition at line 95 of file ScopedTemporaryValue.h.
1.8.17