Pigweed
 
Loading...
Searching...
No Matches
pw::ScopeGuard< Functor > Class Template Reference

#include <scope_guard.h>

Public Member Functions

constexpr ScopeGuard (Functor &&functor)
 
constexpr ScopeGuard (ScopeGuard &&other) noexcept
 
template<typename OtherFunctor >
constexpr ScopeGuard (ScopeGuard< OtherFunctor > &&other)
 
ScopeGuardoperator= (ScopeGuard &&other) noexcept
 
 ScopeGuard (const ScopeGuard &)=delete
 
ScopeGuardoperator= (const ScopeGuard &)=delete
 
void Dismiss ()
 

Detailed Description

template<typename Functor>
class pw::ScopeGuard< Functor >

ScopeGuard ensures that the specified functor is executed no matter how the current scope exits, unless it is dismissed.

Example:

pw::Status SomeFunction() {
PW_TRY(OperationOne());
ScopeGuard undo_operation_one(UndoOperationOne);
PW_TRY(OperationTwo());
ScopeGuard undo_operation_two(UndoOperationTwo);
PW_TRY(OperationThree());
undo_operation_one.Dismiss();
undo_operation_two.Dismiss();
return pw::OkStatus();
}
Definition: scope_guard.h:38
Definition: status.h:85
constexpr Status OkStatus()
Definition: status.h:234

Member Function Documentation

◆ Dismiss()

template<typename Functor >
void pw::ScopeGuard< Functor >::Dismiss ( )
inline

Dismisses the ScopeGuard, meaning it will no longer execute the Functor when it goes out of scope.


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