An RAII class that changes the value of a variable and reverts it to the original value on destruction.
More...
|
| template<typename U, bool OPT = IS_OPTIONAL> |
| | scoped_value_change (T &ref, U new_val, typename std::enable_if_t<!OPT > *=0) noexcept(std::is_nothrow_move_constructible_v< T >) |
| template<typename U, bool OPT = IS_OPTIONAL> |
| | scoped_value_change (T &ref, U new_val, typename std::enable_if_t< OPT > *=0) noexcept(std::is_nothrow_move_constructible_v< T > &&std::is_nothrow_copy_constructible_v< T >) |
|
| scoped_value_change (const scoped_value_change &)=delete |
| | scoped_value_change (scoped_value_change &&other) noexcept(std::is_nothrow_move_constructible_v< T >) |
|
scoped_value_change & | operator= (const scoped_value_change &)=delete |
|
scoped_value_change & | operator= (scoped_value_change &&other)=delete |
| | Move assignment is not implemented because it's not clear and obvious what the order of reversions would be, and I don't want to force the user to read and remember the documentation.
|
| bool | valid () const noexcept |
| T const & | original_value () const &noexcept |
| | Returns the original value.
|
| T | original_value () &&noexcept(std::is_nothrow_move_constructible_v< T >) |
| | Returns the original value.
|
| T const & | current_value () |
| | Returns the current value.
|
| void | revert () noexcept(std::is_nothrow_move_assignable_v< T >) |
| | Reverts the value to the original one.
|
| T | revert_and_return () noexcept(std::is_nothrow_move_assignable_v< T > &&std::is_nothrow_move_constructible_v< T >) |
| | Reverts the value to the original one.
|
| void | release () noexcept |
| | Causes the value to not be reverted on destruction.
|
| T | release_and_return () noexcept(std::is_nothrow_move_constructible_v< T >) |
| | Causes the value to not be reverted on destruction.
|
template<typename T, bool IS_OPTIONAL = false>
struct ghassanpl::scoped_value_change< T, IS_OPTIONAL >
An RAII class that changes the value of a variable and reverts it to the original value on destruction.
Not exception-safe (probably).
Definition at line 264 of file scope.h.