www.mooseframework.org
Public Member Functions | Public Attributes | List of all members
OnScopeExit Struct Reference

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)
 
OnScopeExitoperator= (OnScopeExit &&other)
 
 ~OnScopeExit ()
 

Public Attributes

std::function< void()> _f
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ OnScopeExit() [1/2]

OnScopeExit::OnScopeExit ( std::function< void()>  f)
inlinenoexcept

Definition at line 53 of file ComputeFVFluxThread.h.

53 : _f(std::move(f)) {}
std::function< void()> _f

◆ OnScopeExit() [2/2]

OnScopeExit::OnScopeExit ( OnScopeExit &&  other)
inline

Definition at line 54 of file ComputeFVFluxThread.h.

54 : _f(std::move(other._f)) {}
std::function< void()> _f

◆ ~OnScopeExit()

OnScopeExit::~OnScopeExit ( )
inline

Definition at line 60 of file ComputeFVFluxThread.h.

61  {
62  if (_f)
63  _f();
64  }
std::function< void()> _f

Member Function Documentation

◆ operator=()

OnScopeExit& OnScopeExit::operator= ( OnScopeExit &&  other)
inline

Definition at line 55 of file ComputeFVFluxThread.h.

56  {
57  _f = std::move(other._f);
58  return *this;
59  }
std::function< void()> _f

Member Data Documentation

◆ _f

std::function<void()> OnScopeExit::_f

Definition at line 52 of file ComputeFVFluxThread.h.

Referenced by operator=(), and ~OnScopeExit().


The documentation for this struct was generated from the following file: