This works like the Sentinel helper classes in MOOSE, except it is more flexible and concise to use. More...
#include <ComputeFVFluxThread.h>
Public Member Functions | |
OnScopeExit (std::function< void()> f) noexcept | |
OnScopeExit (OnScopeExit &&other) | |
OnScopeExit & | operator= (OnScopeExit &&other) |
~OnScopeExit () | |
Public Attributes | |
std::function< void()> | _f |
This works like the Sentinel helper classes in MOOSE, except it is more flexible and concise to use.
You just initialize it with a lambda and can return it from within another function scope. So a function that has other cleanup functions associated with it can just wrap those cleanup funcs in an OnScopeExit object and return it. The caller of the function needing cleanup simply catches its return value and voila - the cleanup function are called at the end of the calling functions scope. Like this:
OnScopeExit doSomethingSpecial() { ... return OnScopeExit([]{cleanupSomethingSpecial();}); } void cleanupSomethingSpecial() {...}
void main() { auto cleaner_uper = doSomethingSpecial(); }
Definition at line 50 of file ComputeFVFluxThread.h.
|
inlinenoexcept |
Definition at line 53 of file ComputeFVFluxThread.h.
|
inline |
Definition at line 54 of file ComputeFVFluxThread.h.
|
inline |
Definition at line 60 of file ComputeFVFluxThread.h.
|
inline |
Definition at line 55 of file ComputeFVFluxThread.h.
std::function<void()> OnScopeExit::_f |
Definition at line 52 of file ComputeFVFluxThread.h.
Referenced by operator=(), and ~OnScopeExit().