|
Cbeam
|
A helper that sets the given variable to a new value, and restores the original value on destruction. More...
#include <scoped_set.hpp>
Public Types | |
| using | ValueType = typename extract_atomic_value_type<T>::type |
Public Member Functions | |
| scoped_set (T &instance, ValueType newVal) | |
Constructs a scoped_set and assigns newVal to instance. | |
| virtual | ~scoped_set () noexcept |
| Destructor that restores the original value of the managed variable. | |
A helper that sets the given variable to a new value, and restores the original value on destruction.
This class can handle both normal and std::atomic variables. On construction, it stores the old value, then sets the variable to the new value. On destruction, it reverts the variable back to the original value.
| T | The type of the managed variable (normal or atomic). |
| using cbeam::lifecycle::scoped_set< T >::ValueType = typename extract_atomic_value_type<T>::type |
|
inline |
Constructs a scoped_set and assigns newVal to instance.
Stores the previous value, which is restored on destruction.
| instance | A reference to the variable to manage. |
| newVal | The new value to set temporarily. |
|
inlinevirtualnoexcept |
Destructor that restores the original value of the managed variable.