TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
triqs::utility::scope_guard< F >

#include <triqs/utility/scope_guard.hpp>

Detailed Description

template<class F>
class triqs::utility::scope_guard< F >

RAII wrapper that invokes a callable when it goes out of scope, unless dismissed.

Template Parameters
FCallable type.

Definition at line 40 of file scope_guard.hpp.

Public Member Functions

 scope_guard ()=delete
 Default construction is disabled: a guard must always wrap a callable.
 scope_guard (const scope_guard &)=delete
 Copy construction is disabled: a guard owns a unique cleanup action.
 scope_guard (F f)
 Construct a guard from a callable.
 scope_guard (scope_guard &&rhs) noexcept
 Move constructor.
 ~scope_guard ()
 Destructor.
bool active () const
 Query whether the guard is still active.
void dismiss ()
 Disable the guard so the stored callable is not invoked on destruction.
scope_guardoperator= (const scope_guard &)=delete
 Copy assignment is disabled: a guard owns a unique cleanup action.
scope_guardoperator= (scope_guard &&rhs) noexcept
 Move assignment.

Constructor & Destructor Documentation

◆ scope_guard() [1/2]

template<class F>
triqs::utility::scope_guard< F >::scope_guard ( F f)
inline

Construct a guard from a callable.

The callable is run in the destructor unless dismiss() is called first.

Parameters
fCallable to store and run at scope exit.

Definition at line 50 of file scope_guard.hpp.

◆ ~scope_guard()

template<class F>
triqs::utility::scope_guard< F >::~scope_guard ( )
inline

Destructor.

Invokes the stored callable if the guard is still active.

Definition at line 56 of file scope_guard.hpp.

◆ scope_guard() [2/2]

template<class F>
triqs::utility::scope_guard< F >::scope_guard ( scope_guard< F > && rhs)
inlinenoexcept

Move constructor.

Takes ownership of the callable and dismisses the other guard so the action runs only once.

Parameters
rhsGuard to move from. It is left dismissed afterwards.

Definition at line 82 of file scope_guard.hpp.

Member Function Documentation

◆ active()

template<class F>
bool triqs::utility::scope_guard< F >::active ( ) const
inline

Query whether the guard is still active.

Returns
True if the stored callable will run on destruction, false if dismissed.

Definition at line 69 of file scope_guard.hpp.

◆ operator=()

template<class F>
scope_guard & triqs::utility::scope_guard< F >::operator= ( scope_guard< F > && rhs)
inlinenoexcept

Move assignment.

Swaps the stored callable and activity flag with the other guard.

Parameters
rhsGuard to move from.
Returns
Reference to *this.

Definition at line 95 of file scope_guard.hpp.


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