|
TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
|
#include <triqs/utility/scope_guard.hpp>
RAII wrapper that invokes a callable when it goes out of scope, unless dismissed.
| F | Callable 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_guard & | operator= (const scope_guard &)=delete |
| Copy assignment is disabled: a guard owns a unique cleanup action. | |
| scope_guard & | operator= (scope_guard &&rhs) noexcept |
| Move assignment. | |
|
inline |
Construct a guard from a callable.
The callable is run in the destructor unless dismiss() is called first.
| f | Callable to store and run at scope exit. |
Definition at line 50 of file scope_guard.hpp.
|
inline |
Destructor.
Invokes the stored callable if the guard is still active.
Definition at line 56 of file scope_guard.hpp.
|
inlinenoexcept |
Move constructor.
Takes ownership of the callable and dismisses the other guard so the action runs only once.
| rhs | Guard to move from. It is left dismissed afterwards. |
Definition at line 82 of file scope_guard.hpp.
|
inline |
Query whether the guard is still active.
Definition at line 69 of file scope_guard.hpp.
|
inlinenoexcept |
Move assignment.
Swaps the stored callable and activity flag with the other guard.
| rhs | Guard to move from. |
Definition at line 95 of file scope_guard.hpp.