![]() |
dfx 0.1.0
Linux-based dynamic dataflow executor
|
Scope guard that executes a callable when it goes out of scope. More...
#include <dfx-utilities/ExecOnOOS.hpp>
Public Member Functions | |
| ExecOnOOS (bool exec, F &&f) noexcept | |
| Construct a scope guard. | |
| ExecOnOOS (F &&f) noexcept | |
| Construct an enabled scope guard. | |
| ~ExecOnOOS () noexcept(std::is_nothrow_invocable_v< F >) | |
| Destructor. Executes the stored callable if not cancelled. | |
| void | cancel () noexcept |
| Prevent execution on scope exit. | |
| bool | willExec () const noexcept |
| Return whether the callable will currently execute on scope exit. | |
Public Attributes | |
| F | cb |
| Stored callable executed on destruction if shouldExec is true. | |
| bool | shouldExec |
| Whether the destructor should execute cb. | |
Scope guard that executes a callable when it goes out of scope.
ExecOnOOS ("execute on out-of-scope") is a tiny RAII helper: it stores a callable and calls it from the destructor if it has not been cancelled.
Typical use-cases:
| F | Callable type. Must be invocable with no arguments: cb(). |
The destructor's noexcept specification is conditional on whether F is nothrow-invocable.
|
inlinenoexcept |
Construct a scope guard.
| exec | If true, the callable will be executed on scope exit. |
| f | Callable to store. |
|
inlinenoexcept |
Construct an enabled scope guard.
Equivalent to ExecOnOOS(true, std::move(f)).
| f | Callable to store. |
|
inlinenoexcept |
Destructor. Executes the stored callable if not cancelled.
Calls cb() only if shouldExec is true at destruction time.
|
inlinenoexcept |
Prevent execution on scope exit.
After calling this, the destructor will not invoke the callable.
|
inlinenoexcept |
Return whether the callable will currently execute on scope exit.
| F dfx::Utils::ExecOnOOS< F >::cb |
Stored callable executed on destruction if shouldExec is true.
| bool dfx::Utils::ExecOnOOS< F >::shouldExec |
Whether the destructor should execute cb.