Run a function on scope exit (movable version). More...
#include <MovableOnScopeExit.hpp>
Public Member Functions | |
template<typename FunctionT > | |
MovableOnScopeExit (FunctionT function) | |
Run the function on scope exit. More... | |
MovableOnScopeExit (MovableOnScopeExit &&rhs) noexcept | |
Move the scope exit running to a different instance. More... | |
void | clear () |
Set to the function to NOP (cancels scheduled execution). More... | |
void | executeNow () |
Execute the function now and then clear it. More... | |
Run a function on scope exit (movable version).
This class should be used as a stack based instance. The template constructor takes a function pointer or lambda expression. This function is run when the scope within which the instance is defined exits, unless the instance is moved out of the scope.
If the instance is moved, the old instance will not run the function on destruction. This allows the instance to be set up in an inner scope and moved to the calling scope without the function running at the end of the inner scope.
|
inlineexplicit |
Run the function on scope exit.
|
inlinenoexcept |
Move the scope exit running to a different instance.
|
inline |
Set to the function to NOP (cancels scheduled execution).
|
inline |
Execute the function now and then clear it.