Functor to run some code when this variable goes out of scope. More...
#include <mostlyharmless_OnScopeExit.h>
Public Member Functions | |
OnScopeExit (std::function< void(void)> &&action) | |
~OnScopeExit () noexcept | |
Functor to run some code when this variable goes out of scope.
Useful for performing some action after a function returns, for example:
Will print "Hello world" after the function body has run.
Lifetime concerns apply here, be very very careful.
|
explicit |
Constructs an OnScopeExit.
action | An rvalue ref to an action to perform when this object gets destroyed. |
|
noexcept |
Destructor - the lambda you passed to the constructor will be executed here.