ADTF  3.18.2
ScopeGuard< F >

Scope guard executing a callable object of type F on scope exit. More...

Public Member Functions

 ScopeGuard (const ScopeGuard &)=delete
 
ScopeGuardoperator= (const ScopeGuard &)=delete
 
ScopeGuardoperator= (ScopeGuard &&other)=delete
 
 ScopeGuard (ScopeGuard &&other)
 
 ScopeGuard (F &&f)
 Ctor. More...
 
 ~ScopeGuard ()
 Destroy the scope guard object and execute the callable if execution is enabled.
 
void dismiss () noexcept
 Dismiss the execution of the callable on scope exit.
 
void rehire () noexcept
 Rehire the execution of the callable on scope exit.
 

Private Attributes

bool _enabled = true
 
std::decay< F >::type _f
 

Detailed Description

template<class F>
class a_util::ScopeGuard< F >

Scope guard executing a callable object of type F on scope exit.

The callable execution can be disabled/re-enabled by using dismiss() or rehire() respectively (default: enabled).

To actually create scope guards objects, the following convenience functions are provided:

Template Parameters
FType of the callable object (pointer to function, lambda, etc.)

Definition at line 56 of file scopeguard.h.

Constructor & Destructor Documentation

◆ ScopeGuard()

ScopeGuard ( F &&  f)
inlineexplicit

Ctor.

Parameters
[in]fThe callable object to execute on scope exit

Definition at line 76 of file scopeguard.h.